/**
 * Copyright (c) 2007,中企动力华南研发中心
 * All rights reserved.
 */
package com.ce.pms.customer.web;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.hibernate.exception.ConstraintViolationException;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.service.IBankAccountService;
import com.ce.pms.charge.service.IBankCollectionService;
import com.ce.pms.charge.service.IFeeBankService;
import com.ce.pms.common.model.SysInfo;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.StringAnalysiUtil;
import com.ce.pms.common.web.ICacheManage;
import com.ce.pms.customer.model.ClientRHouseDO;
import com.ce.pms.customer.model.IdTypeDO;
import com.ce.pms.customer.model.ProRightDO;
import com.ce.pms.customer.service.IClientRHouseService;
import com.ce.pms.customer.service.IConstService;
import com.ce.pms.customer.service.ICustomerService;
import com.ce.pms.customer.vo.CustSearchVO;
import com.ce.pms.customer.vo.CustomerHouseVO;
import com.ce.pms.customer.vo.CustomerVO;
import com.ce.pms.customer.vo.IndividualVO;
import com.ce.pms.customer.vo.InterestVO;
import com.ce.pms.customer.vo.MoveVO;
import com.ce.pms.customer.vo.OrganizationVO;
import com.ce.pms.customer.vo.ResidentVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.house.service.IProRightChangeService;
import com.ce.pms.house.vo.HouseVO;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.components.xtable.util.ExtremeUtils;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.annotation.Scope;
import com.sitechasia.webx.core.support.Page;

/**
 *
 * 	名称: com.ce.pms.customer.web.CustomerAction <br>
 *
 *
 * @author  罗军林  <br>
 * Created on： 22008-5-22 <br>
 * @author <br>
 * update on： <br>
 * why: <br>
 */
public class CustomerAction extends PmsBaseAction {


	/**
	 * 住户集合key
	 */
	public static final String WEBCACHE_KEY_CUSTOMER_ALL = "customerAllColletion";

	/**
	 * 判断验证时的操作是新增业主资料的新增页面
	 */
	protected static final String AT_ADD = "isAddAdd";

	/**
	 * 判断验证时的操作是新增业主资料的修改页面
	 */
	protected static final String AT_ADD_EDIT = "isAddEdit";

	/**
	 * 判断验证时的操作是修改业主资料的修改页面
	 */
	protected static final String AT_EDIT = "isEdit";

	/**
	 * 删除状态返回值
	 */
	protected static final String DELETE_STATE = "deleted";

	/**
	 * 房屋已存在于缓存中
	 */
	protected static final String HOUSE_EXIST_IN_SESSION = "existInList";

	/**
	 * 房号为空
	 */
	protected static final String HOUSENO_ISNULL = "houseno_isnull";

	/**
	 * 从业务上来说最后的房子，如房子是产权共有的那两间房也是一个整体，
	 * 能删除则一起删除，不能删除也只能同时留下
	 */
	protected static final String IS_LAST_HOUSE = "isOneHouse";

	/**
	 * 正常状态返回值
	 */
	protected static final String NORMAL_STATE = "true";

	/**
	 * 不存在时返回
	 */
	protected static final String NOT_EXIST = "notExist";

	/**
	 * 判空值时返回
	 */
	protected static final String NULL_STATE = "false";

	/**
	 * 用于确认一个业主基本资料已经确认在缓存列表中
	 */
	private static final String IS_FULL_EXIST = "fullExitCache";

	/**
	 * 用于确认一个业主基本资料在缓存列表中根本不存在，
	 * 在这种情况下，系统会同时验证这个业主是否与缓存中房屋建立关系
	 */
	private static final String IS_FULL_NOTEXIST = "fullNotExist";

	/**
	 * 用于在修改一个业主基本资料时，是否没有改变而直接保存
	 */
	private static final String IS_ONESELF_EXIST = "isOneself";
	
	private static final String LESSEE_RELATION = "lessee";
	private static final String MEMBER_RELATION = "member";
	private static final String OWNER_RELATION = "owner";

	protected IBankAccountService bankAccountService;

	protected  IBankCollectionService collectionService;

	/**
	 * 基本资料已存在于缓存中
	 */
	protected final String CUSTOMER_EXIST_IN_SESSION = "existCache";

	/**
	 * 住户服务类接口
	 */
	protected ICustomerService customerService;

	protected IFeeBankService feeBankService;

	protected IHouseService houseService;

	protected IProRightChangeService proRightChangeService;

	private IClientRHouseService clientRHouseService;

	private IConstService constService;

	/**
	 *
	 * 功能描述: 添加住户信息，包括业主和租户，这些信息将从缓存中取得
	 * 此方法应该被其子类重写以实现真正的业务逻辑
	 *
	 * @author 付湘辉
	 * Created on:2008-6-3
	 *
	 * 修改原因：
	 * @return String 返回结果
	 */
	public String addCustomer() {
		   return null;
	}

	/**
	* 将住户的住房信息添加到缓存中，这些信息可能有多个，
	* 此方法应该被其子类重写以实现真正的业务逻辑
	* @param customerHouseVO 住户住房信息
	* @return String
	*/
	public String addCustomerHouseCache(@Read(key = "ec_p")Integer currentPage,
										@Read(key = "ec_crd")Integer pageSize,
										@Read CustomerHouseVO customerHouseVO) {
		   return null;
	}

	/**
	 * 功能描述：在指定key的缓存集合中添加一个住户VO对象
	 * 		   由标志isFirst决定是添加到缓存头还是尾部
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerVO
	 *            待添加的住户VO对象
	 * @param isFirst
	 *            添加到头尾标志
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public boolean addOneCustomerBaseToCache(String key, CustomerVO customerVO, boolean isFirst) {
		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}
		boolean returnValue =  false;

		if (BlankUtil.isBlank(customerVO)) {
			return returnValue;
		}

		LinkedList<ICacheManage> list = (LinkedList<ICacheManage>) this.getRequest()
				.getSession().getAttribute(key);

		if (list == null) {
			list = new LinkedList<ICacheManage>();
		}else if(list.contains(customerVO)){
			returnValue = this.JudgeResumDeleteCustomerFromCache(key, customerVO)==null?false:true;
			return returnValue;
		}

		customerVO.setHasSave(ICacheManage.UNSAVE);//未保存过
		customerVO.setOpratorStatus(ICacheManage.ADD);//操作状态

		customerVO.setIndex(this.generationCacheIndex(list));//设置索引

		if (isFirst) {
			list.addFirst(customerVO);
		}else {
			list.addLast(customerVO);
		}

		Collections.sort(list);

		this.getRequest().getSession().setAttribute(key, list);
		returnValue = true;

		return returnValue;
	}

	/**
	 * 功能描述：在指定key的缓存集合中添加一个住房信息VO对象
	 * 		   由标志isFirst决定是添加到缓存头还是尾部
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerHouseVO
	 *            待添加的住房信息VO对象
	 * @param isFirst
	 *            添加到头尾标志
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public boolean addOneCustomerHouseToCache(String key, CustomerHouseVO customerHouseVO, boolean isFirst) {
		if (BlankUtil.isBlank(key) || BlankUtil.isBlank(customerHouseVO)) {
			return false;
		}
		LinkedList<ICacheManage> list = (LinkedList<ICacheManage>) this.getRequest()
				.getSession().getAttribute(key);
		boolean flag =  false;
		if (list == null) {
			list = new LinkedList<ICacheManage>();
		}else if(list.contains(customerHouseVO)){
			flag = this.JudgeResumDeleteHouseFromCache(key, customerHouseVO)==null ? false : true;
			return flag;
		}

		customerHouseVO.setHasSave(ICacheManage.UNSAVE);//是否保存过
		customerHouseVO.setOpratorStatus(ICacheManage.ADD);//操作状态

		customerHouseVO.setIndex(this.generationCacheIndex(list));//设置索引

		if (isFirst) {
			list.addFirst(customerHouseVO);
		}else {
			list.addLast(customerHouseVO);
		}

		this.getRequest().getSession().setAttribute(key, list);
		flag = true;

		return flag;
	}

	/**
	 *
	 * 功能描述: 检查系统中是否已存在指定的证件类型和证件号码
	 *
	 * @author 付湘辉
	 * Created on:2008-6-4
	 *
	 * 修改原因：
	 * @param idTypeId　证件类型
	 * @param idNO　证件号码
	 * @return
	 * @return boolean 返回结果
	 */
	public boolean checkIdTypeAndIdNoExclusive(@Read(key="certificateType") String certificateTypeId,
			@Read(key="certificateNo") String certificateNo){
		IndividualVO ivo=this.customerService.queryParticipant(certificateTypeId, certificateNo);

		return ivo != null;
	}

	/**
	 *
	 * 功能描述: 在点击关闭按钮时检查缓存数据是否改动
	 *
	 * @author 付湘辉
	 * Created on:2008-6-16
	 *
	 * 修改原因：
	 * @param customerTypeCode 住户类型编码
	 * @return String 返回结果
	 */
	public void closeCheckCache(@Read(key="customerTypeCode")String customerTypeCode){
		List<CustomerHouseVO> houseList = null;
		List<CustomerVO> customerList = null;
		String houseKey = "";
		String flag = null;

		if (CustomerVO.OWNER_CODE.equals(customerTypeCode)) {
			houseKey = OwnerAction.WEBCACHE_KEY_OWNER_HOUSE;
		}else if (CustomerVO.LESSEE_CODE.equals(customerTypeCode)) {
			houseKey = LesseeAction.WEBCACHE_KEY_LESSEE_HOUSE;
		}

		houseList = this.getCustomerHouseListCacheHerebyFlag(houseKey, false);

		for (CustomerHouseVO houseVO : houseList) {
			if (ICacheManage.UNSAVE.equals(houseVO.getHasSave())
					|| !ICacheManage.DONE.equals(houseVO.getOpratorStatus())) {
				this.renderText("no");//缓存中数据有更改
				return;
			}
		}

		customerList = this.getCustomerBaseListCacheHerebyFlag(false);

		//如果有一个是空的,而另一个不为空时
		if (BlankUtil.isBlank(houseList) && !BlankUtil.isBlank(customerList)
				|| !BlankUtil.isBlank(houseList) && BlankUtil.isBlank(customerList)) {
			this.renderText("no");//缓存中数据有更改
			return;
		}

		for (CustomerVO customerVO : customerList) {
			if (ICacheManage.UNSAVE.equals(customerVO.getHasSave())
					|| !ICacheManage.DONE.equals(customerVO.getOpratorStatus())) {
				this.renderText("no");//缓存中数据有更改
				return;
			}
		}

		this.renderText(flag == null?"yes":flag);
	}
	public void customerLiveIn(@Read(key="moveInDate")String moveInDate){
		MoveVO moveInvo = (MoveVO)this.getAttribute("moveIn", Scope.SESSION);
		moveInvo.setCreator(super.getUserId());
		moveInvo.setMoveDate(moveInDate);
		this.customerService.customerLiveIn(moveInvo);
	}
	/**
	* Function:住户搬出处理
	* Create author:yixianjian
	* Create on:2008-6-17
	* Edit author:
	* Edit on:
	* Why:
	 */
	public void customerMoveOut(@Read(key="moveOutDate")String moveOutDate){

		MoveVO movevo = (MoveVO)this.getAttribute("moveIn", Scope.SESSION);
		movevo.setMoveDate(moveOutDate);
		movevo.setCreator(super.getUserId());
		this.customerService.customerMoveOut(movevo);
	}

	/**
	 * 功能描述: 删除一个住户(包括业主和租户，在删除住户时同时删除家庭成员信息) <br>
	 * @param participantId 参与人id
	 * @param participantTypeCode 参与人类型（001 个人,002 组织）
	 * @param customerTypeCode 客户类型(001 业主，002 租户)
	 *
	 * Create author: <br>
	 * Create on:2008-6-17  <br>
	 * Edit author:付湘辉  <br>
	 * Edit on: 2008-10-23   <br>
	 * Why:     <br>
	 */
	public void deleteCustomer(@Read(key="participantID")Long participantId,
			@Read(key="participantTypeCode")String participantTypeCode,
			@Read(key="customerTypeCode")String customerTypeCode){
		String returnStr = "";
		try {
			// 如果是租户
			if (SysrefcodeDO.CLIENT_TYPE_LESSEE.equals(customerTypeCode)) {
				returnStr=this.customerService.deleteLesseeCustomer(participantId, participantTypeCode);
			// 如果是业主
			} else if (SysrefcodeDO.CLIENT_TYPE_OWNER.equals(customerTypeCode)) {
				returnStr=this.customerService.deleteOwnerCustomer(participantId, participantTypeCode);
			}
		} catch (BusinessException be) {
			throw be;
		} catch (ConstraintViolationException ce) {
			throw new BusinessException("customer:customer_delete_fail_exception",
					BusinessException.WARNING);
		}

		if ("existCharge".equals(returnStr)) {
			this.renderText("false");
		}else{
			this.renderText("true");
		}

	}

	/**
	 * 功能描述：在指定key的缓存集合中删除一个住户VO对象，包括个人和组织，
	 * 如果该对象并没有持久化过，则直接从缓存中删除，否则
	 * 将其操作状态改为删除状态
	 *
	 * @author 付湘辉
	 * Created on 2008-05-29
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerVO
	 *            待删除的住户VO对象
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public boolean deleteOneCustomerBaseFromCache(String key, CustomerVO customerVO) {
		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key,false);
		boolean flag =  false;
		if (!list.contains(customerVO)) {
			return flag;
		}
		for (CustomerVO cusVO : list) {
			if (cusVO.getIndex().equals(customerVO.getIndex())) {
				if (ICacheManage.UNSAVE.equals(cusVO.getHasSave())) {
					list.remove(cusVO);
					this.getRequest().getSession().setAttribute(key, list);
				}else{
					cusVO.setOpratorStatus(ICacheManage.DELETE);//操作状态
				}
				flag = true;
				break;
			}
		}
		return flag;
	}
	/**
	 * 功能描述：在指定key的缓存集合中删除一个住房信息VO对象，
	 * 如果该对象并没有持久化过，则直接从缓存中删除，否则
	 * 是将其操作状态改为删除状态<br>
	 * 此方法要求参数CustomerHouseVO对象覆写<b>Object.equals()<b>方法
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerHouseVO
	 *            待删除的住房信息VO对象
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public boolean deleteOneCustomerHouseFromCache(String key, CustomerHouseVO customerHouseVO) {
		boolean flag =  false;

		if (BlankUtil.isBlank(key)) {
			return flag;
		}

		LinkedList<CustomerHouseVO> list = (LinkedList<CustomerHouseVO>) this.getRequest()
				.getSession().getAttribute(key);

		if (!list.contains(customerHouseVO)) {
			return flag;
		}

		if (list != null) {
			for (CustomerHouseVO houseVO : list) {
				if (houseVO.getIndex().equals(customerHouseVO.getIndex())) {
					if (ICacheManage.SAVED.equals(houseVO.getHasSave())) {
						houseVO.setOpratorStatus(ICacheManage.DELETE);//如果已保存了则改变操作状态
					}else{
						list.remove(houseVO);//移除
						this.getRequest().getSession().setAttribute(key, list);
					}
					flag = true;
					break;
				}
			}
		}

		return flag;

	}

	/**
	 *
	 * 功能描述: 在当前住户管理列表页面点击编辑按钮
	 * <b>注意：<b>在进入此功能时，应先清空会话中缓存信息，以保证数据准确性。
	 * @author 许海堆
	 * Created on:2008-6-12
	 *
	 * 修改原因：
	 * @param participantId 参与人id
	 * @param participantTypeCode 参与人类型编码
	 * @param customerTypeCode 住户类型编码
	 * @return String 返回结果
	 */
	public String editCustomer(@Read(key="participantID")Long participantId,
                                    			@Read(key="participantTypeCode")String participantTypeCode,
                                    			@Read(key="customerTypeCode")String customerTypeCode){
		//清空缓存
		this.clearCache();
		//如果是租户
		if(CustomerVO.LESSEE_CODE.equals(customerTypeCode)){
			//清空缓存
			this.getRequest().getSession().removeAttribute(LesseeAction.WEBCACHE_KEY_LESSEE_HOUSE);

			List<CustomerHouseVO> listHouse =this.customerService.getClientRHouseBy(participantId,customerTypeCode);

			for(CustomerHouseVO house : listHouse){
		    	this.addOneCustomerHouseToCache(LesseeAction.WEBCACHE_KEY_LESSEE_HOUSE, house, false);
			}

			this.setAllStatusToDone(LesseeAction.WEBCACHE_KEY_LESSEE_HOUSE);

			if(CustomerVO.INDIVIDUAL_CODE.equals(participantTypeCode)) {
				IndividualVO individual = this.customerService.findIndividualById(participantId);
				individual.setCustomerType(CustomerVO.LESSEE_INDIVIDUAL);
				individual.setCustomerTypeCode(CustomerVO.LESSEE_CODE);
				individual.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);
				individual.setCreator(this.getUserId());
	           this.addOneCustomerBaseToCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, individual, false);
			} else if (CustomerVO.ORGNIZATION_CODE.equals(participantTypeCode)) {
				OrganizationVO organization = this.customerService.findOrganizationById(participantId);
				organization.setCustomerType(CustomerVO.LESSEE_ORGNIZATION);
				organization.setCustomerTypeCode(CustomerVO.LESSEE_CODE);
				organization.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);
				organization.setCreator(this.getUserId());
				this.addOneCustomerBaseToCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, organization, false);
			}

			  this.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);

			this.getRequest().getSession().setAttribute("participantTypeCode", participantTypeCode);
			this.getRequest().getSession().setAttribute("participantId", participantId);
			return "initLesseeEditMain";
		}

		//如果是业主
        if(CustomerVO.OWNER_CODE.equals(customerTypeCode)) {
        	//清空业主住房信息缓存
        	this.getRequest().getSession().removeAttribute(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);

        	//如果是个人业主
        	if(CustomerVO.INDIVIDUAL_CODE.equals(participantTypeCode)) {
				IndividualVO individual = this.customerService.findIndividualById(participantId);

				individual.setCustomerType(CustomerVO.OWNER_INDIVIDUAL);
				individual.setCustomerTypeCode(CustomerVO.OWNER_CODE);
				individual.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);

				individual.setCreator(this.getUserId());
				//添加到缓存
	            this.addOneCustomerBaseToCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, individual, false);

				this.getRequest().getSession().setAttribute("type", "001");
			} else if (CustomerVO.ORGNIZATION_CODE.equals(participantTypeCode)) {//企业业主
				OrganizationVO organization = this.customerService.findOrganizationById(participantId);
				organization.setCustomerType(CustomerVO.OWNER_ORGNIZATION);
				organization.setCustomerTypeCode(CustomerVO.OWNER_CODE);
				organization.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);
				organization.setCreator(this.getUserId());

				//添加到缓存
	            this.addOneCustomerBaseToCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, organization, false);

				this.getRequest().setAttribute("type", "002");
			}
			this.getRequest().getSession().setAttribute("participantTypeCode", participantTypeCode);
			this.getRequest().getSession().setAttribute("participantId", participantId);
			this.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
			return "ownerEditMain";
		}

		return null;
	}

	/**
	 * 功能描述：在指定key的缓存集合中修改一个住户VO对象，包括个人和组织
	 *
	 * @author 付湘辉
	 * Created on 2008-05-29
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerVO
	 *            待修改的住户VO对象
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public boolean editOneCustomerBaseAsCache(String key, CustomerVO customerVO) {
		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}

		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key, false);

		boolean returnValue =  false;

		if (!list.contains(customerVO)) {
			return returnValue;
		}

		//判断在缓存中是否已存在证件类型号码相同的个人或企业名称相同的组织
		for (CustomerVO vo : list) {
			if (CustomerVO.INDIVIDUAL_CODE.equals(vo.getParticipantTypeCode())
					&& vo.getCertificateType().equals(customerVO.getCertificateType())
					&& vo.getCertificateNo().equalsIgnoreCase(customerVO.getCertificateNo())) {

				if (vo.getIndex().equals(customerVO.getIndex())) {
					break;
				} else {
					return returnValue;
				}
			}else{
				if (vo.getParticipantName().equalsIgnoreCase(customerVO.getParticipantName())) {
					if (vo.getIndex().equals(customerVO.getIndex())) {
						break;
					} else {
						return returnValue;
					}
				}
			}

		}


		CustomerVO tempCusVo = null;
		IndividualVO tempIvo = null;
		OrganizationVO tempOvo = null;
		IndividualVO paramIvo = null;
		OrganizationVO paramOvo = null;

		for (CustomerVO customVO : list) {
			if (customVO.getIndex().equals(customerVO.getIndex())) {

				tempCusVo = list.remove(list.indexOf(customVO));

				if (CustomerVO.INDIVIDUAL_CODE.equals(tempCusVo.getParticipantTypeCode())) {
					tempIvo =  (IndividualVO)tempCusVo;
					paramIvo = (IndividualVO)customerVO;
					this.editIndividualCustomerInner(paramIvo, tempIvo);//修改个人
				}else{
					tempOvo = (OrganizationVO)tempCusVo;
					paramOvo = (OrganizationVO)customerVO;
					this.editOrganizationCustomerInner(paramOvo, tempOvo);//修改组织
				}

				tempCusVo.setOpratorStatus(ICacheManage.EDIT);//操作状态

				returnValue = true;
				break;
			}
		}
		if (returnValue) {
			list.addFirst(tempCusVo);
			this.getRequest().getSession().setAttribute(key, list);
		}
		return returnValue;
	}


	/**
	 * 功能描述：在指定key的缓存集合中修改一个住房信息VO对象
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerHouseVO
	 *            待修改的住房信息VO对象
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public boolean editOneCustomerHouseAsCache(String key, CustomerHouseVO customerHouseVO) {
		if (BlankUtil.isBlank(key)) {
			return false;
		}
		LinkedList<CustomerHouseVO> list = (LinkedList<CustomerHouseVO>) this.getRequest()
				.getSession().getAttribute(key);

		boolean flag =  false;

		if (!list.contains(customerHouseVO)) {
			return flag;
		}

		CustomerHouseVO tempCusVo = null;

		if (list != null) {
			for (CustomerHouseVO houseVO : list) {
				if (houseVO.getIndex().equals(customerHouseVO.getIndex())) {
//					tempCusVo = list.remove(list.indexOf(houseVO));
					tempCusVo = houseVO;

					tempCusVo.setHouseContractNumber(customerHouseVO.getHouseContractNumber());//合同号
					tempCusVo.setHousePropertyNo(customerHouseVO.getHousePropertyNo());//产权证号
					this.updateCustomerHouseBankAccValues(customerHouseVO, tempCusVo);
					//tempCusVo.setOwnerName(customerHouseVO.getOwnerName());//业主姓名（这只在租户修改中涉及，暂不启用）
					tempCusVo.setOpratorStatus(ICacheManage.EDIT);//操作状态

					list.remove(list.indexOf(houseVO));
					flag = true;
					break;
				}
			}
		}

		if (flag) {
			list.addFirst(tempCusVo);
			this.getRequest().getSession().setAttribute(key, list);
		}

		return flag;

	}

	/**
	 *
	 * 功能描述: 得到所有兴趣爱好VO的列表
	 *
	 * @author 付湘辉
	 * Created on:2008-5-30
	 *
	 * 修改原因：
	 * @return
	 * @return List 返回结果
	 */
	public List<InterestVO> getAllInterestList(){
		return this.customerService.getAllInterestList();
	}

	/**
	 * Function: 读取表CS_ID_TYPE中的证件类型信息
	 * @return
	 * Create author:燕大为
	 * Create on:2008-5-29
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public List<IdTypeDO> getCertificateType()
	{
		return  this.constService.getCertificateType();
	}
	/**
	 *
	 * 功能描述: 根据证件类型id获得证件类型名称
	 *
	 * @author 燕大为
	 * Created on:2008-6-12
	 *
	 * 修改原因：
	 * @param idType
	 * @return String 返回结果
	 */
	public String getCertifiCateTypeName(Long idType) {

		List<IdTypeDO> certificate = this.getCertificateType();
		StringBuffer sbcertificate = new StringBuffer();

		for (IdTypeDO id : certificate) {
			if (id.getIdTypeId().equals(idType)) {
				sbcertificate.append(id.getIdTypeName());
				break;
			}
		}

		return sbcertificate.toString();
	}
	/**
	 * 方法描述: 获取缓存中相对应有效的客户VO列表，此方法由家庭成员维护块调用
	 * @author 胡煦
	 * Create on:2008-5-30
	 *
	 * Edit author:付湘辉
	 * Edit on:2008-5-30
	 * 修改原因：增加方法体实现
	 * @return List<CustomerVO>
	 */
	public List<CustomerVO> getCustomerListForMemberCache(){
		List<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(true);
		List<CustomerVO> resultList = new ArrayList<CustomerVO>();

		for (CustomerVO customerVO : list) {
			if (ICacheManage.SAVED.equals(customerVO.getHasSave())) {
				resultList.add(customerVO);
			}
		}

		return resultList;
	}

	/**
	 *
	 * 功能描述: 获取缓存中相对应有效的客户房屋id列表，此方法由家庭成员维护块调用
	 *
	 * @author 付湘辉
	 * Created on:2008-6-13
	 *
	 * 修改原因：
	 * @param key 缓存中住房信息key值
	 * @return List 返回结果
	 */
	public List<Long> getHouserIdListForMemberFromCache(String key){

		List<CustomerHouseVO> list = this.getCustomerHouseListCacheHerebyFlag(key, true);
		List<Long> resultList = new ArrayList<Long>();

		for (CustomerHouseVO customerHouseVO : list) {
			if (ICacheManage.SAVED.equals(customerHouseVO.getHasSave())) {
				resultList.add(customerHouseVO.getHouseId());
			}
		}

		return resultList;
	}


	/**
	 *
	 * 功能描述: 根据证件类型和号码从缓存查询个人记录，在所查询的记录集已过滤了删除状态
	 *
	 * @author 付湘辉
	 * Created on:2008-7-4
	 *
	 * 修改原因：
	 * @param key
	 * @param certificateType
	 * @param certificateNo
	 * @return CustomerVO 返回结果
	 */
	public CustomerVO getOneCustomerBaseBycertificateTypeAndNoFromCache(String key,Long certificateType,String certificateNo){
		if (BlankUtil.isBlank(certificateType)
				|| BlankUtil.isBlank(certificateNo)) {
			return null;
		}

		//返回过滤了已置为删除态的记录
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key, true);

		for (CustomerVO customerVO : list) {
			if (CustomerVO.INDIVIDUAL_CODE.equals(customerVO
					.getParticipantTypeCode())
					&& certificateType.equals(customerVO.getCertificateType())
					&& certificateNo.equalsIgnoreCase(customerVO
							.getCertificateNo())) {
				return customerVO;
			}
		}

		return null;
	}

	/**
	 * 功能描述：通过住户id在指定key的缓存集合中查找一个住户信息VO对象，
	 *
	 * @author 付湘辉
	 * Created on 2008-06-17
	 * @param key
	 *            在缓存中的key
	 * @param participantId
	 *            参与人id
	 * @return CustomerVO
	 */
	@SuppressWarnings("unchecked")
	public CustomerVO getOneCustomerBaseByIdFromCache(String key, Long participantId) {
		CustomerVO customer = null;
		if (BlankUtil.isBlank(participantId)) {
			return null;
		}

		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key, false);

		if (list == null) {
			return null;
		}

		for (CustomerVO customerVO : list) {
			if (participantId.equals(customerVO.getParticipantId())) {
				customer =  customerVO;
				break;
			}
		}

		return customer;
	}

	/**
	 * 功能描述：通过房屋索引(index)在指定key的缓存集合中查找一个住户信息VO对象，
	 *
	 * @author 付湘辉
	 * Created on 2008-05-29
	 * @param key
	 *            在缓存中的key
	 * @param participantId
	 *            参与人id
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public CustomerVO getOneCustomerBaseByIndexFromCache(String key, Integer index) {
		if (BlankUtil.isBlank(index)) {
			return null;
		}
		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key, false);

		if (list == null) {
			return null;
		}

		for (CustomerVO customerVO : list) {
			if (index.equals(customerVO.getIndex())) {
				return customerVO;
			}
		}
		return null;
	}


	/**
	 *
	 * 功能描述: 根据企业名称从缓存中查询组织记录，在所查询的记录集已过滤了删除状态
	 *
	 * @author 付湘辉
	 * Created on:2008-7-4
	 *
	 * 修改原因：
	 * @param key
	 * @param certificateType
	 * @param certificateNo
	 * @return CustomerVO 返回结果
	 */
	public CustomerVO getOneCustomerBaseByOrgNameFromCache(String key,String participantName){
		if (BlankUtil.isBlank(key)
				|| BlankUtil.isBlank(participantName)) {
			return null;
		}

		//返回过滤了已置为删除态的记录
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key, true);

		for (CustomerVO customerVO : list) {
			if (CustomerVO.ORGNIZATION_CODE.equals(customerVO.getParticipantTypeCode())
					&& participantName.equalsIgnoreCase(customerVO.getParticipantName())) {
				return customerVO;
			}
		}

		return null;
	}

	/**
	 * 功能描述：通过房屋Id在指定key的缓存集合中查找一个住房信息VO对象，
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 * @param key
	 *            在缓存中的key
	 * @param houseId
	 *            住房信息id
	 * @return boolean
	 */
	@SuppressWarnings("unchecked")
	public CustomerHouseVO getOneCustomerHouseByHouseIdFromCache(String key, Long houseId) {
		if (BlankUtil.isBlank(houseId) || BlankUtil.isBlank(key)) {
			return null;
		}

		LinkedList<CustomerHouseVO> list = (LinkedList<CustomerHouseVO>) this.getRequest()
				.getSession().getAttribute(key);

		if (list != null) {
			for (CustomerHouseVO houseVO : list) {
				if (houseId.equals(houseVO.getHouseId())) {
					return houseVO;
				}
			}
		}

		return null;
	}

	/**
	 *
	 * 功能描述: 通过房屋号在指定key的缓存集合中查找一个住房信息VO对象，
	 *
	 * @author 付湘辉
	 * Created on:2008-6-26
	 *
	 * 修改原因：
	 * @param key
	 * @param houseNumber
	 * @return CustomerHouseVO 返回结果
	 */
	public CustomerHouseVO getOneCustomerHouseByHouseNumberFromCache(String key, String houseNumber) {
		if (BlankUtil.isBlank(houseNumber) || BlankUtil.isBlank(key)) {
			return null;
		}

//		LinkedList<CustomerHouseVO> list = (LinkedList<CustomerHouseVO>) getRequest()
//				.getSession().getAttribute(key);
		LinkedList<CustomerHouseVO> list = this.getCustomerHouseListCacheHerebyFlag(key, true);

		if (list != null) {
			for (CustomerHouseVO houseVO : list) {
				if (houseNumber.equalsIgnoreCase(houseVO.getHouseNumber())) {
					return houseVO;
				}
			}
		}

		return null;
	}

	/**
	 * 功能描述：通过证件类型和证件号码在指定key的缓存集合中查找一个个人住户信息VO对象，
	 *
	 * @author 付湘辉
	 * Created on 2008-06-17
	 * @param key
	 *            在缓存中的key
	 * @param certificateType
	 * 			  证件类型
	 * @param certificateNo
	 *            证件号码
	 * @return IndividualVO
	 */
	@SuppressWarnings("unchecked")
	public IndividualVO getOneIndividualByIdAndNoFromCache(String key,Long certificateType,String certificateNo){
		IndividualVO individual = null;
		if (BlankUtil.isBlank(certificateType)|| BlankUtil.isBlank(certificateNo)) {
			return null;
		}

		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key, false);

		if (list == null) {
			return null;
		}

		for (CustomerVO customerVO : list) {
			if (CustomerVO.INDIVIDUAL_CODE.equals(customerVO.getParticipantTypeCode())
					&& certificateNo.equalsIgnoreCase(customerVO.getCertificateNo())
					&& certificateType.equals(customerVO.getCertificateType())) {
				individual = (IndividualVO) customerVO;
				break;
			}
		}

		return individual;
	}

	/**
	 * 功能描述：通过住户参与人名称在指定key的缓存集合中查找一个企业住户信息VO对象，
	 *
	 * @author 付湘辉
	 * Created on 2008-06-17
	 * @param key
	 *            在缓存中的key
	 * @param participantName
	 *            参与人名称
	 * @return OrganizationVO
	 */
	@SuppressWarnings("unchecked")
	public OrganizationVO getOneOrganizationByNameFromCache(String key, String participantName) {
		OrganizationVO organizationVO = null;
		if (BlankUtil.isBlank(participantName)) {
			return null;
		}

		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(key, false);

		if (list == null) {
			return null;
		}

		for (CustomerVO customerVO : list) {
			if (CustomerVO.ORGNIZATION_CODE.equals(customerVO.getParticipantTypeCode())
					&& participantName.equals(customerVO.getParticipantName())) {
				organizationVO = (OrganizationVO) customerVO;
				break;
			}
		}

		return organizationVO;
	}

	/**
	 * Function: 根据性别ID查询性别显示值
	 * @param sexId
	 * @return
	 * Create author:燕大为
	 * Create on:2008-6-11
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String getSexDisplayValueById(Long sexId)
	{
		if (BlankUtil.isBlank(sexId)) {
			return "";
		}

		SysrefcodeDO sysref = this.sysrefcodeService.findSysrefcodeById(sexId);
		if (BlankUtil.isBlank(sysref)) {
			return "";
		}else{
			return sysref.getName();
		}
//		if(Long.valueOf(17l).equals(sexId))
//		{
//			SysrefcodeDO sys = (SysrefcodeDO) sysrefcodeService.querySysrefCodesByCode("CS_INDIVIDUAL_SEX", "1").get(0);
//			return sys.getName();
//		}
//		else
//		{
//			SysrefcodeDO sys = (SysrefcodeDO) sysrefcodeService.querySysrefCodesByCode("CS_INDIVIDUAL_SEX", "0").get(0);
//			return sys.getName();
//		}
	}

	/**
	* Function:初始化选择住户记录
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-12
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initCustomerChoose(@Read(key="customerId") Long customerId,
									 @Read(key="houseId") Long houseId){
		MoveVO moveInVO = this.customerService.queryCustomerBy(customerId, houseId);
		this.setAttribute("moveIn", moveInVO,Scope.SESSION);
		return "customerChoose";
	}

	/**
	 * Function:初始化列表页面，根据业务需要，<br/>
	 * 			这里仅做页面跳转,初始时不做查询
	 * Create author:罗军林
	 * Create on:2008-6-4
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void initCustomerList(){
//		Object totalRows=getAttribute("totalRows");
//		if(totalRows==null){
			this.setAttribute("totalRows", new Integer(0));
//		}
	}

	/**
	 * Function:跳转到当前住户管理的首页面cusomerMain.jsp
	 * Create author:罗军林
	 * Create on:2008-5-22
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void initCustomerMain() {
		
	}

	/**
	 * Function:跳转到高级查询页面customerSearch.jsp
	 * Create author:罗军林
	 * Create on:2008-5-26
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void initCustomerSearch(){}

	/**
	 * 方法描述: 初始化个人住户资料
	 *
	 * @author 付湘辉 Create on:2008-5-22
	 * @param participantId
	 *            参与人ID
	 * @return
	 */
	public String initIndividual(@Read(key="participantId") Long participantId) {

		IndividualVO individualVO = new IndividualVO();
		individualVO = this.customerService.findIndividualById(participantId);

		this.setAttribute("individual", individualVO);
		return "initIndividual";
	}

	/**
	* Function:居住管理入住
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initLiveIn(@Read(key="customerType")String customerType,
							 @Read(key="houseNumber") String houseNumber){
		Date sysDate = this.customerService.getDate();
		this.setAttribute("sysDate", sysDate, Scope.REQUEST);
		if(StringUtils.isNotBlank(customerType)) {
			this.setAttribute("customerLinve_customerType", customerType,Scope.SESSION);
		}
		return "residentLiveIn";
	}

	/**
	* Function:居住管理，搬出
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initMoveOut(@Read(key="customerType")String customerType,
			 				@Read(key="houseNumber") String houseNumber){
		Date sysDate = this.customerService.getDate();
		this.setAttribute("sysDate", sysDate, Scope.REQUEST);
		if(StringUtils.isNotBlank(customerType)) {
			this.setAttribute("customerLinve_customerType", customerType,Scope.SESSION);
		}
		return "residentMoveOut";
	}

	/**
	 * 方法描述: 初始化企业住户资料
	 *
	 * @author 付湘辉 Create on:2008-5-22
	 * @param participantId
	 *            参与人ID
	 * @return
	 */
	public String initOrganization(@Read(key="participantId") Long participantId) {
		OrganizationVO organizationVO = this.customerService.findOrganizationById(participantId);
		this.setAttribute("organization", organizationVO);
		return "initOrganization";
	}

	/**
	 *
	* Function:初始化居住管理主页面
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initResident(){
		return "residentMain";
	}

	/**
	* Function:居住管理列表页面
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initResidentList(){
		this.setAttribute("totalRows", Integer.valueOf("0"));
		return "residentList";
	}

	/**
	* Function:居住管理高级查询页面
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String initResidentSearch(){
		return "residentSearch";
	}

	/**
	 * Function:<p>在EC TABLE组件调用此方法。</p>
	 * 			<p>查询前将会取出缓存中的查询条件对象，然后再执行普通查询</p>
	 * @param pageNO
	 * @param pageSize
	 * @return
	 * Create author:罗军林
	 * Create on:2008-6-12
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String pageSearch(	@Read(key = "ec_p",defaultValue="1")	Integer pageNO,
								@Read(key = "ec_crd",defaultValue="15") Integer pageSize) {
		CustSearchVO custSearchVO;
		Object obj=this.getAttribute("custsearchVO",Scope.SESSION);
		custSearchVO= obj==null ? new CustSearchVO() : (CustSearchVO)obj;
		return this.mySearch(custSearchVO, pageNO, pageSize);
	}

	/**
	 * Function: 输入房号带出房主与房屋ID
	 * @param houseNumber
	 * Create author:燕大为
	 * Create on:2008-6-13
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void queryCustomerHouse(@Read(key="houseNumber") String houseNumber)
	{
		houseNumber = houseNumber.trim();
		List<CustomerHouseVO> house = this.customerService.getHouseAndCustomerBy(houseNumber);
		if(!BlankUtil.isBlank(house)){//有业主
			String jsonStr=this.generationHouseJSON(house);
			this.renderText(jsonStr);
		}else{
			HouseVO houseVO =this.customerService.getHouseByHouseNumber(houseNumber);
			if(!BlankUtil.isBlank(houseVO)){//无业主
				StringBuffer jsonStr = new StringBuffer("{");
				jsonStr.append("\"houseId\" : \""+ houseVO.getKeyword() +"\",");
				jsonStr.append("\"houseNumber\" : \""+ houseVO.getHouseNumber() +"\",");
				jsonStr.append("\"ownerName\" : \"\"");
				jsonStr.append("}");
				this.renderText(jsonStr.toString());
			}
		}

	}

	/**
	 * Function:根据企业名称查询企业所有信息包括企业基本信息,法人代表,代理人信息。
	 * @param participantName
	 * @return
	 * Create author:罗军林
	 * Create on:2008-5-30
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void queryOrganizationAllByName(@Read(key="participantName") String participantName)
	{
		Object[] objs = this.customerService.queryAllOrganization(participantName);
		if(objs[0] == null || objs[1] == null || objs[2] == null){
			this.renderText("false");
		}else{
			CustomerVO temp = this.JudgeResumDeleteCustomerFromCache(WEBCACHE_KEY_CUSTOMER_ALL, ((OrganizationVO)objs[0]));

			String jsonStr="";
			if (temp!=null) {
				jsonStr=this.generationOrganizationJSON((OrganizationVO)temp);
			}else{
				jsonStr=this.generationOrganizationAllJSON(objs);
			}

			this.renderText(jsonStr);
		}
	}

	/**
	 * Function:根据企业名称查询企业信息。
	 * @param participantName
	 * @return
	 * Create author:罗军林
	 * Create on:2008-5-30
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void queryOrganizationByName(	@Read(key="participantName") String participantName){
		OrganizationVO organizationVO=this.customerService.queryOrganizationByName(participantName);

		if(organizationVO==null){
			this.renderText("false");
		}else{
			String jsonStr=this.generationOrganizationJSON(organizationVO);
			this.renderText(jsonStr);
		}
	}

	/**
	 * Function:根据证件类型id和证件号码查询
	 * @param idTypeCode
	 * @param idNO
	 * @return
	 * Create author:罗军林
	 * Create on:2008-5-30
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void queryParticipant(@Read(key="certificateType") String idTypeId,
								 @Read(key="certificateNo")   String idNO){
		IndividualVO ivo=this.customerService.queryParticipant(idTypeId, idNO);

		if(ivo==null){
			this.renderText("false");
		}else{
			CustomerVO temp = this.JudgeResumDeleteCustomerFromCache(WEBCACHE_KEY_CUSTOMER_ALL, ivo);
			String jsonStr=this.generationParticipantJSON(temp==null?ivo:(IndividualVO)temp);
			this.renderText(jsonStr);
		}
	}

	public void renderCustomerList(){

	}


	/**
	 * Function:根据用户条件查询
	 * @param custsearchVO
	 * @param pageNO
	 * @param pageSize
	 * @return
	 * Create author:罗军林
	 * Create on:2008-5-22
	 * Edit
	 * author:
	 * Edit on:
	 * Why:
	 */
	public String search(	@Read	CustSearchVO custsearchVO,
							@Read(key = "ec_p",defaultValue="1")	Integer pageNO,
							@Read(key = "ec_crd",defaultValue="15") Integer pageSize) {
		return this.mySearch(custsearchVO, pageNO, pageSize);
	}

	/**
	* Function:居住管理查询
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-10
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String searchResident(@Read(key = "ec_p",defaultValue="1")	Integer pageNO,
									@Read(key = "ec_crd",defaultValue="15") Integer pageSize){
		Object object = this.getAttribute("serchCondition", Scope.SESSION);
		CustSearchVO custsearchVO = object==null?new CustSearchVO():(CustSearchVO)object;
		custsearchVO.setOrderString(ExtremeUtils.getOrderString(getRequest()));

		Page page  = this.customerService.queryResidentInfo(custsearchVO, pageNO, pageSize);
		List<ResidentVO> list = this.generationResidentViewData(page.getResult());
		this.setAttribute("residentList", list);
		this.setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));
		return "residentList";
	}

	public void setBankAccountService(IBankAccountService bankAccountService) {
		this.bankAccountService = bankAccountService;
	}

	public void setClientRHouseService(IClientRHouseService clientRHouseService) {
		this.clientRHouseService = clientRHouseService;
	}

	public void setCollectionService(IBankCollectionService collectionService) {
		this.collectionService = collectionService;
	}



	public void setConstService(IConstService constService) {
		this.constService = constService;
	}

	public void setCustomerService(ICustomerService customerService) {
		this.customerService = customerService;
	}

	/**
	 * Function:将查询条件保存至session,高级查询时将调用本方法,然后再由页面调用search方法
	 * @param custsearchVO
	 * Create author:罗军林
	 * Create on:2008-6-17
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public void setCustsearchVOCache(@Read	CustSearchVO custsearchVO) {
		this.setAttribute("custsearchVO", custsearchVO,Scope.SESSION);
	}

	/**
	 * @param feeBankService the feeBankService to set
	 */
	public void setFeeBankService(IFeeBankService feeBankService) {
		this.feeBankService = feeBankService;
	}


	public void setHouseService(IHouseService houseService) {
		this.houseService = houseService;
	}

	public void setProRightChangeService(
			IProRightChangeService proRightChangeService) {
		this.proRightChangeService = proRightChangeService;
	}

	/**
	* Function:保存高级查询的条件
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-17
	* Edit author:
	* Edit on:
	* Why:
	 */
	public void setSearchResidentCondition(@Read	CustSearchVO custsearchVO){
		this.setAttribute("serchCondition", custsearchVO, Scope.SESSION);
	}

	/**
	 * 功能描述: 入住时,需要先验证是否有没有搬出的房间,有需要先搬出再入住.
	 * <br>这里存在这样的一个问题,如果有入住没搬出的房间,最好是抛异常,但目前的异常处理不支持参数所以没法处理只好在页面处理。
	 * <br>这里的做法 及其恶心  jsp和action有耦合  action同dao有耦合  ....
	 * @param vo  需要入住的房间
	 * Create author:yixianjian <br>
	 * Create on:2008-11-21  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void validationAllowMoveIn(@Read CustSearchVO vo){
		List<ClientRHouseDO> list = clientRHouseService.getClientRHouseListByHouseIdAndClientType(
												vo.getHouseId(),
												vo.getClientId());
		String houseNumbers = getHouseNumberList(list);
		if(houseNumbers == null) this.renderText("pass");//没有入住后没有搬出的记录
		else this.renderText(houseNumbers);//有入住但没搬出记录,则直接返回房号
	}

	/**
	 * 功能描述: 此验证用于前台失去焦点时调用 <br>
	 * @param houseNumber
	 * @param cacheKey
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String validationHouseForRenderText(String houseNumber, String cacheKey){
		String rendText =  this.checkHouseNo(houseNumber, cacheKey);
		if (!CustomerAction.NORMAL_STATE.equalsIgnoreCase(rendText) && !CustomerAction.DELETE_STATE.equalsIgnoreCase(rendText)) {
			super.renderText(rendText);
		} else if (CustomerAction.DELETE_STATE.equalsIgnoreCase(rendText)) {
			super.renderText(CustomerAction.NORMAL_STATE);
		} else {
			rendText = this.checkHouseAndCustomerList(houseNumber, true);
			if (!BlankUtil.isBlank(rendText)) {
				super.renderText(rendText);
			}else{
				super.renderText(CustomerAction.NORMAL_STATE);
			}
		}
		
		return null;
	}

	/**
	 * 功能描述：验证页面所选或所输入房号,在点击保存或确定按钮时调用
	 *
	 * @author 付湘辉
	 * Created on 2008-05-27
	 *
	 * @param houseNumber
	 * @return String
	 */
	public void validationHouseOnSave(@Read(key="houseNumber") String houseNumber,
														   String cacheKey) {
		String resultString = this.checkHouseNo(houseNumber,cacheKey);
		if (CustomerAction.NULL_STATE.equalsIgnoreCase(resultString)) {
			throw new BusinessException("customer:owner_must_choose_house_exception",
					BusinessException.WARNING);
		}else if (CustomerAction.NOT_EXIST.equalsIgnoreCase(resultString)) {
			throw new BusinessException("house:house_number_not_exist_exception",
					BusinessException.WARNING);
		}else if (CustomerAction.HOUSE_EXIST_IN_SESSION.equalsIgnoreCase(resultString)) {
			throw new BusinessException("customer:customer_list_has_exist_house_exception",
					BusinessException.WARNING);
		}else if (CustomerAction.DELETE_STATE.equalsIgnoreCase(resultString)) {
			return;
		}

		this.checkHouseAndCustomerList(houseNumber, false);
	}

	/**
	 *
	 * 功能描述: 判断传入的参数是否有一个为空，
	 * 如果是则抛出参数为空异常,参数 key 由调用者 传入
	 *
	 * @author 付湘辉
	 * Created on:2008-7-10
	 *
	 * @author
	 * Update on：
	 * 修改原因：
	 * @exception com.ce.pms.exception.BusinessException
	 * @param parameters
	 * @param key
	 */
	protected void checkIsException(String key,Object ... parameters){
		this.checkIsException(key, null, parameters);
	}

	/**
	 *
	 * 功能描述: 判断传入的参数是否有一个为空，如果是则抛出参数为空异常,参数 key 由调用者 传入
	 * 默认的异常类型是waring
	 * @author 付湘辉
	 * Created on:2008-7-10
	 *
	 * @author
	 * Update on：
	 * 修改原因：
	 * @exception com.ce.pms.exception.BusinessException
	 *
	 * @param key
	 * @param type
	 * @param parameters
	 */
	protected void checkIsException(String key,String type,Object ... parameters){
		if (!BlankUtil.isBlank(parameters)) {
			for (Object object : parameters) {
				if (BlankUtil.isBlank(object)) {
					throw new BusinessException(key,type==null?BusinessException.WARNING:type);
				}
			}
		}else{
			throw new BusinessException(key,type==null?BusinessException.WARNING:type);
		}
	}

	/**
	 * 功能描述：清空缓存数据
	 *
	 * @author 付湘辉
	 *
	 * Created on  2008-05-22
	 * @return String
	 * @roseuid 4827E0DC00BB
	 */
	protected String clearCache() {
		this.getRequest().getSession().removeAttribute(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);

		return "ok";
	}

	/**
	 * 功能描述：删除已存到缓存中的住房信息，
	 * 如果customerHouseVO有产权共有的合并房，则会连带删除那此房间，如果删除后缓存中没有任何有效房间，则操作中断。
	 *
	 * @author 付湘辉
	 *
	 * Created on  2008-05-23
	 * @param customerHouseVO 住房信息
	 * @return String
	 * @roseuid 482A8C0E0213
	 */
	protected void deleteCustomerHouseCache(CustomerHouseVO customerHouseVO,String cacheKey) {
		String result = CustomerAction.NORMAL_STATE;
        int size = 1;
        //通过房子id查到缓存中的房屋
        CustomerHouseVO tempchvo = this.getOneCustomerHouseByHouseIdFromCache(cacheKey, customerHouseVO.getHouseId());
        List<CustomerHouseVO> list = new LinkedList<CustomerHouseVO>();
        //检查这间房是否有产权共有的合并房屋，有则要将它们视为一个整体
        if (!BlankUtil.isBlank( tempchvo.getProRightShareHouseIds())) {
            Set<Long> set = tempchvo.getProRightShareHouseIds();
            size = set.size();
            for (Long id : set) {
				list.add(this.getOneCustomerHouseByHouseIdFromCache(cacheKey, id));
			}
        }else{
        	list.add(tempchvo);
        }
        //如果这间房屋已保存过并且现在缓存中只余下最后一间房，则不能删除它
        if (/*ICacheManage.SAVED.equals(tempchvo.getHasSave())
                &&*/ this.getCustomerHouseListCacheHerebyFlag(cacheKey, true).size() <= size) {
            result = CustomerAction.IS_LAST_HOUSE;
        } else {
            for (CustomerHouseVO houseVO : list) {
            	//进行删除动作
                if (!this.deleteOneCustomerHouseFromCache(cacheKey, houseVO)) {
                    result = CustomerAction.NULL_STATE;
                    break;
                }
            }
        }
		this.renderText(result);
	}

	/**
	 * 功能描述: 过滤掉已存在兴趣爱好
	 *
	 * @author 付湘辉
	 * Created on:2008-6-3
	 *
	 * 修改原因：
	 * @param interestString
	 * @param interestList
	 * @return void
	 */
	protected void filtrateExistentInterest(String interestString, List<InterestVO> interestList,List<InterestVO> removeList) {
		String[]interestArray=null;

		if (removeList==null) {
			removeList = new ArrayList<InterestVO>();
		}else if (!removeList.isEmpty()) {
			removeList.clear();
		}

		if (interestString!=null) {
			interestArray = interestString.split(SysInfo.SEPARATOR_COMMA);

			outer:
			for (String string : interestArray) {
				for (InterestVO interestVO : interestList) {
					if (string.equals(interestVO.getInterestId().toString())) {
						removeList.add(interestList.remove(interestList.indexOf(interestVO)));
						continue outer;
					}
				}
			}
		}
	}

	/**
	 * 功能描述：从住户基本资料缓存中查询住户基本资料信息分页列表
	 *
	 * @author 付湘辉
	 * Created on 2008-05-29
	 *
	 * @param currentPage 当前页码
	 * @param pageSize 页大小
	 * @return List 一个住户基本资料信息的分页列表
	 */
	@SuppressWarnings("unchecked")
	protected List<CustomerVO> findCustomerBaseListCachePage(Integer currentPage,Integer pageSize){
		LinkedList<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(true);
		if (list==null) {
			return new ArrayList<CustomerVO>();
		}

		List<CustomerVO> resultList = this.paginationList(currentPage, pageSize, list);

		return resultList;
	}

	/**
	 *
	 * 功能描述: 得到缓存中住户资料列表，如果没有数据，此方法返回一个实例化的空列表容器<br>
	 * 操作标志<b>opratorFlag</b>：<br>如果此参数为<b><i>true</i></b>值，则会返回一个过滤了删除状态记录的列表，<br>
	 * 否则完整返回
	 *
	 * @see this{@link #getCustomerBaseListCacheHerebyFlag(String, boolean)}
	 * @author 付湘辉
	 * Created on:2008-5-30
	 *
	 * Edit on：2008-6-3
	 * 修改原因：增加操作标志参数opratorFlag
	 * @param opratorFlag 操作标志
	 * @return LinkedList<CustomerVO> 返回结果
	 */
	@SuppressWarnings("unchecked")
	protected LinkedList<CustomerVO> getCustomerBaseListCacheHerebyFlag(boolean opratorFlag) {
		return this.getCustomerBaseListCacheHerebyFlag(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, opratorFlag);
	}

	/**
	 * 功能描述: 得到缓存中住户资料列表，如果没有数据，
	 * 此方法返回一个实例化的空列表容器<br>
	 * 操作标志<b>opratorFlag</b>：<br>
	 * 如果此参数为<b><i>true</i></b>值，
	 * 则会返回一个过滤了删除状态记录的列表，否则完整返回。
	 *
	 * @author 付湘辉
	 * Created on:2008-5-30
	 *
	 * Edit on：2008-6-3
	 * 修改原因：增加操作标志参数opratorFlag
	 * @param opratorFlag 操作标志
	 * @param key 缓存key值
	 * @return LinkedList<CustomerVO> 返回结果
	 */
	@SuppressWarnings("unchecked")
	protected LinkedList<CustomerVO> getCustomerBaseListCacheHerebyFlag(String key, boolean opratorFlag) {
		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}

		LinkedList<CustomerVO> list = (LinkedList<CustomerVO>) this.getRequest()
															.getSession().getAttribute(key);

		if (!opratorFlag) {
			return list==null?new LinkedList<CustomerVO>():list;
		}
		LinkedList<CustomerVO> noDelList = new LinkedList<CustomerVO>();

		//把缓存中住户资料操作状态为已删除的过滤掉
		if (list != null) {
			for (CustomerVO customerVO : list) {
				if (ICacheManage.DELETE.equals(customerVO.getOpratorStatus())) {
					continue;
				}
				noDelList.add(customerVO);
			}
		}

		return noDelList;
	}

	/**
	 *
	 * 功能描述:得到缓存中住房信息，如果没有数据，此方法返回一个实例化的空列表容器<br>
	 * 操作标志opratorFlag：如果此参数为<i>true</i>值，则会返回一个过滤了删除状态记录的列表，<br>
	 * 否则完整返回
	 *
	 * @author 付湘辉
	 * Created on:2008-6-3
	 * @return LinkedList<CustomerHouseVO> 返回结果
	 */
	@SuppressWarnings("unchecked")
	protected LinkedList<CustomerHouseVO> getCustomerHouseListCacheHerebyFlag(String key,boolean opratorFlag) {
		if (BlankUtil.isBlank(key)) {
			return new LinkedList<CustomerHouseVO>();
		}

		LinkedList<CustomerHouseVO> list = (LinkedList<CustomerHouseVO>) this.getRequest()
		.getSession().getAttribute(key);

		if (!opratorFlag) {
			return list==null?new LinkedList<CustomerHouseVO>():list;
		}

		LinkedList<CustomerHouseVO> noDelList = new LinkedList<CustomerHouseVO>();

		//把缓存中住房信息操作状态为已删除的过滤掉
		if (list!=null) {
			for (CustomerHouseVO houseVO : list) {
				if (ICacheManage.DELETE.equals(houseVO.getOpratorStatus())) {
					continue;
				}
				noDelList.add(houseVO);
			}
		}

		return noDelList;
	}

	/**
	 * 功能描述: 得到缓存中已删除的住户资料列表
	 *
	 * @author 付湘辉
	 * Created on:2008-5-30
	 *
	 * Edit on：
	 * @param key 缓存key值
	 * @return LinkedList<CustomerVO> 返回结果
	 */
	protected LinkedList<CustomerVO> getDeletedCustomerBaseListCacheHerebyFlag(String key) {
		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}

		//得到全部的
		LinkedList<CustomerVO> allList=new LinkedList<CustomerVO>(this.getCustomerBaseListCacheHerebyFlag(key, false));

		ListIterator<CustomerVO> listIter = allList.listIterator();
		while (listIter.hasNext()) {
			CustomerVO customerVO = listIter.next();
			//把缓存中住户资料操作状态为未删除的过滤掉
			if (!ICacheManage.DELETE.equals(customerVO.getOpratorStatus())) {
				listIter.remove();
			}
		}
		return allList;
	}


	/**
	 * 功能描述：获得指定key的缓存中总记录数
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key 缓存key
	 * @return Integer 总记录数
	 */
	@SuppressWarnings("unchecked")
	protected Integer getTotalRowsFromCache(String key){
		if (BlankUtil.isBlank(key)) {
			return 0;
		}

		LinkedList<ICacheManage> list = (LinkedList<ICacheManage>) this.getRequest()
                                                                                      .getSession().getAttribute(key);
		int totalRows=0;

		if (list!=null) {
			totalRows = list.size();
			for (ICacheManage manage : list) {
				if (ICacheManage.DELETE.equals(manage.getOpratorStatus())) {
					totalRows--;
				}
			}
		}

		return totalRows;
	}

	/**
	 *
	 * 功能描述: 判断这个房间是否有退伙审批表并且状态处于"退伙中" <br>
	 * @author 付湘辉  <br>
	 * Created on:2008-6-20  <br>
	 *
	 * 修改原因：  <br>
	 * @param customerHouseVO
	 * @return boolean true 退伙中 false 不在退伙中
	 */
	protected boolean isTuihuoing(CustomerHouseVO customerHouseVO){

		HouseDomain house = this.houseService.getHouseByNumber(customerHouseVO.getHouseNumber(), false);
		String status = this.proRightChangeService.checkTheHouseNumber(house.getKeyword());
		if (SysrefcodeDO.HM_GO_OUT_FLOW_AUDIT_END.equals(status)||BlankUtil.isBlank(status)) {
			return false;
		}

		return true;
	}

	/**
	 * 功能描述: 将一个列表按参数得到其分页数据部分
	 *
	 * @author 付湘辉
	 * Created on:2008-6-2
	 *
	 * @param currentPage　当前页
	 * @param pageSize　页大小
	 * @param list　列表数据
	 * @return List　分页列表
	 */
	protected List paginationList(Integer currentPage, Integer pageSize, List list) {
		int totalCounts = list.size();
		if (totalCounts < 1) {
			return new ArrayList();
		}

		if (BlankUtil.isBlank(currentPage) || currentPage < 1) {
			currentPage = 1;
		}
		if (BlankUtil.isBlank(pageSize)|| pageSize < 1) {
			pageSize = 5;
		}

		int totalPages = (totalCounts + pageSize - 1) / pageSize ;
		currentPage = currentPage > totalPages ? totalPages : currentPage;

		int fromIndex = Page.getStartOfPage(currentPage, pageSize);
		int toIndex = pageSize * currentPage;

		toIndex = toIndex > totalCounts?totalCounts:toIndex;
		List resultList = list.subList(fromIndex, toIndex);

		return resultList;
	}

	/** 功能描述:  <br>
	 * @param customerVo
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-7-30  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected String queryHouseAndCustomerRelation(CustomerVO customerVo,String houseKey) {
		List<CustomerHouseVO> list = this.getCustomerHouseListCacheHerebyFlag(houseKey, true);
		if (!BlankUtil.isBlank(list)) {
			Long participantId= customerVo.getParticipantId();
			for (CustomerHouseVO houseVO : list) {
				String res = this.customerService.queryClientTypeByParticipantIdAhouse(participantId, houseVO);//     -----到后台验证
				if (!BlankUtil.isBlank(res)) {
					return res;
				}
			}
		}
		return CustomerAction.NORMAL_STATE;
	}

	/**
	 *
	 * 功能描述: 将住房信息和住户信息VO对象的hasSave 和 opratorStatus 设为已保存，
	 * 如果是删除状态的记录全部从列表中移除。
	 *
	 * @author 付湘辉
	 * Created on:2008-6-10
	 *
	 * 修改原因：
	 * @param houseList
	 * @param customerList
	 * @return void
	 */
	protected boolean setAllStatusToDone(String key){
		List<CustomerHouseVO> oldHouseList = null;
		List<CustomerVO> oldCustomerList = null;
		List<CustomerHouseVO> newHouseList = new LinkedList<CustomerHouseVO>();
		List<CustomerVO> newCustomerList = new LinkedList<CustomerVO>();

		if (BlankUtil.isBlank(key)) {
			return false;
		}else if (CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL.equals(key)) {
			oldCustomerList = this.getCustomerBaseListCacheHerebyFlag(false);
			if (!BlankUtil.isBlank(oldCustomerList)) {

				for (CustomerVO customerVO : oldCustomerList) {
					if (ICacheManage.DELETE.equals(customerVO.getOpratorStatus())) {
						newCustomerList.add(customerVO);
					}else{
						customerVO.setHasSave(ICacheManage.SAVED);
						customerVO.setOpratorStatus(ICacheManage.DONE);
					}
				}

				if (!BlankUtil.isBlank(newCustomerList)) {
					oldCustomerList.removeAll(newCustomerList);
				}

				this.getRequest().getSession().setAttribute(key, oldCustomerList);

			}
			return true;
		}else{
			oldHouseList = this.getCustomerHouseListCacheHerebyFlag(key, false);
			if (!BlankUtil.isBlank(oldHouseList)) {
				for (CustomerHouseVO customerHouseVO : oldHouseList) {
					if (ICacheManage.DELETE.equals(customerHouseVO.getOpratorStatus())) {
						newHouseList.add(customerHouseVO);
					}else{
						customerHouseVO.setHasSave(ICacheManage.SAVED);
						customerHouseVO.setOpratorStatus(ICacheManage.DONE);
					}
				}

				if (!BlankUtil.isBlank(newHouseList)) {
					oldHouseList.removeAll(newHouseList);
				}

				this.getRequest().getSession().setAttribute(key, oldHouseList);

			}

			return true;
		}

	}

	/** 功能描述:  <br>
	 * @param sourceCH
	 * @param targetCH
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected void updateCustomerHouseBankAccValues(final CustomerHouseVO sourceCH, CustomerHouseVO targetCH) {
		if (!BlankUtil.isBlank(targetCH.getBankNumber())) {
			if (!this.collectionService.isIn(targetCH.getBankNumber())) {
				throw new BusinessException("charge:charge_bankaccount_not_in_exception,"+targetCH.getBankNumber(),
						BusinessException.ERROR);
			}
		}
		setupBankAccountValues(sourceCH, targetCH);
		LinkedList<CustomerHouseVO> chlist = this.getCustomerHouseListCacheHerebyFlag(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, false);
		for (CustomerHouseVO chvo : chlist) {
			if (ProRightDO.CHARGE_SELECT_MERGER.equals(chvo.getChargeSelect())
					&& (
							(!BlankUtil.isBlank(chvo.getManageHouseId()) &&
								chvo.getManageHouseId().equals(sourceCH.getManageHouseId())
							)
							|| (
									(!BlankUtil.isBlank(chvo.getBankId()) && !BlankUtil.isBlank(chvo.getBankNumber()))
										&& ((chvo.getBankId().equals(sourceCH.getBankId())) && (chvo.getBankNumber().equals(sourceCH.getBankNumber())))
							   )
						)
				) {
				setupBankAccountValues(sourceCH, chvo);
			}
		}
	}

	/** 功能描述: 对客户(业主或租户)在保存验证数据准确性。
	 * 如果是个人客户，检查其证件类型和号码，如果是企业客户，检查其名称。 <br>
	 * 当传入参数ID为空时，查询系统中如果已存在，则抛异常，
	 * 如果ID不为空，查询出来的信息(个人或企业)与此ID不相等，也抛出异常。
	 *
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-11  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected Boolean validateCustomerForIDOnSave(CustomerVO customerVO) {
		Boolean result = false;
		//先验证传入客户
		result = checkCustomerIfIDNull(customerVO);
		if (result) {
			result = checkCustomerIfIDNotNull(customerVO);
//			if (result) {
//				// 对缓存中所有客户验证
//				LinkedList<CustomerVO> linkList = this.getCustomerBaseListCacheHerebyFlag(true);
//		    	for (CustomerVO tmpChvo : linkList) {
//		    		result = checkCustomerIfIDNull(tmpChvo);
//					if (result) {
//						result = checkCustomerIfIDNotNull(tmpChvo);
//						if (!result) {
//							break;
//						}
//					}else{
//						break;
//					}
//				}
//			}
		}
		return result;
	}

	/** 功能描述: 在修改页面点击保存时对客户信息的数据准确性进行验证
	 * 验证不通过将抛出相应异常信息。 <br>
	 * @param operateType TODO
	 * @param individualVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-10-31  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected Boolean validateCustomerOnEditSave(CustomerVO customerVO,String houseKey, String operateType) {
		checkCustomerReauiredField(customerVO);
		if (CustomerVO.INDIVIDUAL_CODE.equals(customerVO.getParticipantTypeCode())) {
			this.validateIndividualLoadOnEditSave((IndividualVO)customerVO, houseKey, operateType);
		}else{
			this.validateOrganizationOnEditSave((OrganizationVO)customerVO,houseKey, operateType);
		}
		// 验证证件类型和号码，企业则验证名称
    	boolean result = this.validateCustomerForIDOnSave(customerVO);
    	return result;
	}

	/** 功能描述: 在新增页面点击保存时对客户信息的数据准确性进行验证
	 * 验证不通过将抛出相应异常信息。 <br>
	 * @param customerVO
	 * @param houseKey
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-10-31  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected Boolean validateCustomerOnSave(CustomerVO customerVO,String houseKey) {
		checkCustomerReauiredField(customerVO);
		Boolean result = false;
		if (CustomerVO.INDIVIDUAL_CODE.equals(customerVO.getParticipantTypeCode())) {
			try {
				this.validateIndividualLoadOnSave((IndividualVO)customerVO, houseKey,CustomerAction.AT_ADD);
			} catch (ClassCastException ce) {
			}

		}else{
			this.validateOrganizationOnSave(customerVO.getParticipantName(),customerVO.getOldParticipantId(), customerVO.getParticipantId(), houseKey);
		}
    	//验证证件类型和号码，企业则验证名称
    	result = this.validateCustomerForIDOnSave(customerVO);
    	return result;
	}
//	private int isValidateIndividualLoadForRenderText = 0;
	/**
	* Function:输入证件类型和证件号码后，
	* 需要确认该证件类型和号码标识的参与人信息是否能导入。
	* (如果对应的参与人已经是业主、租户、家庭成员则不能登记)。 <br>
	* 如果可以导入,则提示用户是否导入。
	* 如果不可以导入，则提示用户，进行相关说明，要求重新填写。<br>
	* 规则：对于局部变量flag的取值意义如下：<br>
	* <ul>
	* <li>true ： 验证通过</li>
	* <li>false ： 正常情况，说明是新的证件类型和号码，不导入也无任何提示</li>
	* <li>existCache ： 已经增加了的</li>
	* <li>001 : 已经是被选房的业主</li>
	* <li>002 : 已经是被选房的租户</li>
	* <li>003 或 004 : 已经是被选房的家庭成员</li>
	* </ul>
	* @param certificateNo 证件号码
	* @param certificateType 证件类型
	* @param oldIndividualId 原有的id
	* @param newIndividualId 新id
	* @param operateType 判断是修改还是新增
	* @param
	* Create author:yixianjian
	* Create on:2008-7-4
	* Edit author:付湘辉
	* Edit on:2008-10-24
	* Why:更改注释
	*/
	protected String validateIndividualLoadForRenderText(IndividualVO individualVO,
										  			  String houseKey,
										  			  String operateType){
//		isValidateIndividualLoadForRenderText=1;
		String flag = CustomerAction.NORMAL_STATE;
		// 判断是否是在缓存中被置删除状态的
		Boolean res = this.checkIsDeleteStatus(individualVO.getCertificateNo(), individualVO.getCertificateType());
		if (res) {
			this.renderText(flag);
			return flag;
		}

		flag=CustomerAction.NULL_STATE;
		String isExist = "";
		try {
			isExist = this.validateIndividualIsExistCache(individualVO.getCertificateType(),
													  individualVO.getCertificateNo(),
													  individualVO.getOldParticipantId(),
													  individualVO.getParticipantId(),
													  operateType,
													  individualVO.getIndex());
		} catch (BusinessException e) {
			if ("customer:owner_exist_same_type_no_exception".equalsIgnoreCase(e.getMessage())) {
				isExist = IS_FULL_EXIST;
			}
		}

		if (IS_FULL_EXIST.equalsIgnoreCase(isExist)) {
			// 这个人已经存在于缓存中了
			flag = this.CUSTOMER_EXIST_IN_SESSION;
		} else if(IS_FULL_NOTEXIST.equalsIgnoreCase(isExist)){
			if (BlankUtil.isBlank(individualVO.getCertificateType())) {
				this.renderText(flag);
				return flag;
			}

			CustomerVO customerVo = this.customerService.queryParticipant(individualVO.getCertificateType().toString(), individualVO.getCertificateNo());
			if(!BlankUtil.isBlank(customerVo)){
				flag = this.queryHouseAndCustomerRelation(customerVo,houseKey);
				if (!CustomerAction.NORMAL_STATE.equalsIgnoreCase(flag)) {
					this.renderText(flag);
					return flag;
				}
			}
		}

		this.renderText(flag);
		return flag;
	}

	/**
	 * <b>功能描述</b>: <p>在新建或修改企业业主时，输入企业名称后，
	 * 需要验证在绶存中是否已经存在相同的名称，
	 * 如果系统中已存在这个企业，验证其与缓存中房屋的关系。</p>
	 * <p>这里的缓存是指页面数据缓存，在新增，修改业主时用到，
	 * 参见 {@link com.ce.pms.common.web.ICacheManage}。</p>
	 * <b>验证规则：</b>
	 * <ol>
	 * <li>如果绶存中已存在该名称的企业，验证不通过。</li>
	 * <li>查询系统中如果已存在这个企业，与缓存中已选择的房屋逐个比较，
	 * 如果这个企业已经是其中一间房的业主或租户，验证不通过。</li>
	 * </ol>
	 * 对于局部变量flag的取值意义如下：<br>
	 * <ul>
	 * <li>true ： 验证通过</li>
	 * <li>false ： 说明是新的企业名称，不导入也无提示，属于正常新增</li>
	 * <li>existCache ： 已经增加了的</li>
	 * <li>001 : 已经是被选房的业主</li>
	 * <li>002 : 已经是被选房的租户</li>
	 * <li>003 或 004 : 已经是被选房的家庭成员</li>
	 * </ul>
	 * @param participantName 企业名
	 * @param oldOrgId 原id
	 * @param newOrgId 新的id
	 * @param operateType 判断是修改还是新增
	 * @param index 缓存信息索引
	 * @author
	 * Create author:付湘辉 <br>
	 * Create on:2008-7-30  <br>
	 * Edit author:付湘辉  <br>
	 * Edit on:2008-10-24  <br>
	 * Why:  修改注释   <br>
	 */
	protected String validateOrganizationLoadForRenderText(OrganizationVO organizationVO,
														   String houseKey,
														   String operateType){
		String flag = CustomerAction.NORMAL_STATE;
		// 判断是否是在缓存中被置删除状态的
		Boolean res = this.checkIsDeleteStatus(organizationVO.getParticipantName());
		if (res) {
			this.renderText(flag);
			return flag;
		}

		flag = CustomerAction.NULL_STATE;
		String isExist = "";
		try {
			isExist = this.validateOrgIsExistCache(organizationVO.getParticipantName(), organizationVO.getOldParticipantId(),organizationVO.getParticipantId(), operateType, organizationVO.getIndex());
		} catch (BusinessException e) {
			if ("customer:owner_exist_same_type_no_exception".equalsIgnoreCase(e.getMessage())) {
				isExist = IS_FULL_EXIST;
			}
		}

		if (IS_FULL_EXIST.equalsIgnoreCase(isExist)) {
			//这个企业已经存在于缓存中了
			flag = this.CUSTOMER_EXIST_IN_SESSION;
		}else if(IS_FULL_NOTEXIST.equalsIgnoreCase(isExist)){
			CustomerVO customerVo = this.customerService.findOrganizationByName(organizationVO.getParticipantName());
			if(!BlankUtil.isBlank(customerVo)){
				flag = this.queryHouseAndCustomerRelation(customerVo,houseKey);
				if (!CustomerAction.NORMAL_STATE.equalsIgnoreCase(flag)) {
					this.renderText(flag);
					return flag;
				}
			}
		}

		this.renderText(flag);
		return flag;
	}

	/** 功能描述: 有id时，检查客户(个人/企业)的数据准确性,
	 * 查询出来的信息(个人或企业)与此ID不相等，也抛出异常 <br>
	 * @param tmpChvo
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-11  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private Boolean checkCustomerIfIDNotNull(CustomerVO tmpChvo) {
		if (tmpChvo.getParticipantId()!=null) {
			if (CustomerVO.INDIVIDUAL_CODE.equals(tmpChvo.getParticipantTypeCode())) {
				IndividualVO indiVo = this.customerService.queryParticipant(tmpChvo.getCertificateType().toString(), tmpChvo.getCertificateNo());
				if (!BlankUtil.isBlank(indiVo)) {
					if (!tmpChvo.getParticipantId().equals(indiVo.getParticipantId())) {
						throw new BusinessException("customer:customer_add_eidt_save_fail_exception",
								BusinessException.WARNING);
					}
				}
			}else if(CustomerVO.ORGNIZATION_CODE.equals(tmpChvo.getParticipantTypeCode())){
				String name = tmpChvo.getParticipantName();
				OrganizationVO org = this.customerService.queryOrganizationByName(name);
				if (!BlankUtil.isBlank(org)) {
					if (!tmpChvo.getParticipantId().equals(org.getParticipantId())) {
						throw new BusinessException("customer:customer_add_eidt_save_org_fail_exception",
								BusinessException.WARNING);
					}
				}
			}
		}
		return true;
	}

	/** 功能描述:没有id时，检查客户(个人/企业)的数据准确性，
	 *  查询系统中如果已存在，则抛异常  <br>
	 * @param tmpChvo
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-11  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private Boolean checkCustomerIfIDNull(CustomerVO tmpChvo) {
		if (tmpChvo.getParticipantId()==null) {
			if (CustomerVO.INDIVIDUAL_CODE.equals(tmpChvo.getParticipantTypeCode())) {
				IndividualVO indiVo = this.customerService.queryParticipant(tmpChvo.getCertificateType().toString(), tmpChvo.getCertificateNo());
				if (!BlankUtil.isBlank(indiVo)) {
					throw new BusinessException("customer:customer_add_eidt_save_fail_exception",
							BusinessException.WARNING);
				}
			}else if(CustomerVO.ORGNIZATION_CODE.equals(tmpChvo.getParticipantTypeCode())){
				String name = tmpChvo.getParticipantName();
				OrganizationVO org = this.customerService.queryOrganizationByName(name);
				if (!BlankUtil.isBlank(org)) {
					throw new BusinessException("customer:customer_add_eidt_save_org_fail_exception",
												BusinessException.WARNING);
				}
			}
		}
		return true;
	}

	/**
	 * 功能描述: 验证必填项。 <br>
	 * @param customerVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void checkCustomerReauiredField(CustomerVO customerVO) {
		if (CustomerVO.INDIVIDUAL_CODE.equals(customerVO.getParticipantTypeCode())) {
			try {
				IndividualVO indivo = (IndividualVO)customerVO;
				indivo.checkRequiredField();
			} catch (ClassCastException ce) {
			}
		}else{
			try {
				OrganizationVO orgvo = (OrganizationVO)customerVO;
				orgvo.checkRequiredField();
			} catch (ClassCastException e) {
			}
		}
	}

	/** 功能描述:  <br>
	 * @param houseNumber
	 * @param isFront
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private String checkHouseAndCustomerList(String houseNumber,Boolean isFront) {
		CustomerHouseVO customerHouseVO = new CustomerHouseVO();
		customerHouseVO.setHouseNumber(houseNumber);
		//查询出当前缓存中的参与人(业主/租户)基本资料列表。
		List<CustomerVO> list = this.getCustomerBaseListCacheHerebyFlag(true);
		String resultString = CustomerAction.NORMAL_STATE;
		if (!BlankUtil.isBlank(list)) {
			for (CustomerVO customerVO : list) {
				if (BlankUtil.isBlank(customerVO.getParticipantId())) {
					continue;
				}
				//查询指定id的参与人是不是指定房间的业主或租户或家庭成员
				if (isFront) {
					resultString = this.customerService.queryClientTypeByParticipantIdAhouse(customerVO.getParticipantId(), customerHouseVO);
				}else{
					resultString = this.customerService.validateParticipantRoleInSameHouse(customerVO.getParticipantId(), customerHouseVO);
				}
				if (!BlankUtil.isBlank(resultString)) {
					if (CustomerAction.OWNER_RELATION.equalsIgnoreCase(resultString)) {
						return StringAnalysiUtil.parseExceptionMessageString(
											super.getLocaleMessage("customer:customer_house_and_person_hasbeen_owner_exception"),
																						Arrays.asList(customerVO.getParticipantName(),
																								customerHouseVO.getHouseNumber()));
						
//						return 
//								"customer:customer_house_and_person_hasbeen_owner_exception,"
//										+ customerVO.getParticipantName()
//										+ ":" + customerHouseVO.getHouseNumber();
					}else if (CustomerAction.LESSEE_RELATION.equalsIgnoreCase(resultString)){
						return StringAnalysiUtil.parseExceptionMessageString(
								super.getLocaleMessage("customer:customer_house_and_person_hasbeen_lessee_exception"),
																			Arrays.asList(customerVO.getParticipantName(),
																					customerHouseVO.getHouseNumber()));
//						return 
//								"customer:customer_house_and_person_hasbeen_lessee_exception,"
//										+ customerVO.getParticipantName()
//										+ ":" + customerHouseVO.getHouseNumber();
					}else if(CustomerAction.MEMBER_RELATION.equalsIgnoreCase(resultString)){
						return StringAnalysiUtil.parseExceptionMessageString(
								super.getLocaleMessage("customer:customer_house_and_person_hasbeen_member_exception"),
																			Arrays.asList(customerVO.getParticipantName(),
																					customerHouseVO.getHouseNumber()));
//						return 
//								"customer:customer_house_and_person_hasbeen_member_exception,"
//										+ customerVO.getParticipantName()
//										+ ":" + customerHouseVO.getHouseNumber();
					}
					break;
				}
			}
		}
		return null;
	}

	/**
	 * 功能描述: 对传入的房号进行查询并检查与之相关的状态。
	 * 在这个方法中，会对业主或租户在缓存中的基本资料进行搜索，
	 * 并对每一个个人或企业信息与指定的房间进行关系查找，找到则返回他们的关系。
	 * 如果业主，租户，业主家庭成员，租户家庭成员，分别返回"001","002","003","004"<br>
	 * @param houseNumber 指定的房间号码
	 * @param cacheKey
	 * @return
	 * 如果返回"true"，说明此房屋状态正常
	 * 如果房号为空返回"false"；
	 * 房号是系统中不存在的，返回"notExist"；
	 * 已选入到缓存列表中，返回"existInList"；
	 * 虽然在缓存中，但是状态是删除的，返回"true"；
	 *
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private String checkHouseNo(String houseNumber, String cacheKey){
		String resultString = CustomerAction.NORMAL_STATE;
		if (BlankUtil.isBlank(houseNumber)) {
			//  请输入或选择一个房间号码
			resultString = CustomerAction.NULL_STATE;
		} else if (BlankUtil.isBlank(this.customerService.getHouseByHouseNumber(houseNumber))) {
			// 不存在的房间号码
			resultString = CustomerAction.NOT_EXIST;
		} else if (this.getOneCustomerHouseByHouseNumberFromCache(cacheKey, houseNumber)!=null) {
			//已经选定的房间号码
			resultString = CustomerAction.HOUSE_EXIST_IN_SESSION;
		}else{
			List<CustomerHouseVO> houseList = this.getDeletedCustomerHouseListCacheHerebyFlag(cacheKey);
			for (CustomerHouseVO houseVO : houseList) {
				//判断是否是在缓存中被置删除状态的
				if (houseNumber.equalsIgnoreCase(houseVO.getHouseNumber())) {
					return DELETE_STATE;
				}
			}
		}

		return resultString;
	}

	/** 功能描述: 检查指定的企业名称是否是缓存中已置删除状态的企业信息 <br>
	 * @param participantName
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private Boolean checkIsDeleteStatus(String participantName) {
		List<CustomerVO> list = this.getDeletedCustomerBaseListCacheHerebyFlag(WEBCACHE_KEY_CUSTOMER_ALL);
		for (CustomerVO customerVO : list) {
			//判断是否是在缓存中被置删除状态的
			if (customerVO.getParticipantName().equalsIgnoreCase(participantName)) {
				return true;
			}
		}
		return false;
	}

	/** 功能描述: 检查指定的证件类型及号码是否是缓存中已置删除状态的个人信息 <br>
	 * @param certificateNo
	 * @param certificateType
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private Boolean checkIsDeleteStatus(String certificateNo, Long certificateType) {
		List<CustomerVO> list = this.getDeletedCustomerBaseListCacheHerebyFlag(WEBCACHE_KEY_CUSTOMER_ALL);
		for (CustomerVO customerVO : list) {
			//判断是否是在缓存中被置删除状态的
			if (customerVO.getCertificateType().equals(certificateType)
					&& customerVO.getCertificateNo().equalsIgnoreCase(certificateNo)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 功能描述：修改一个个人住户属性值
	 *
	 * @author 付湘辉
	 * Created on 2008-05-29
	 *
	 * @param sourceVO 不可更改
	 * @param targetVO
	 */
	private void editIndividualCustomerInner(final IndividualVO sourceVO, IndividualVO targetVO) {
		IndividualVO tempIvo = targetVO;
		final IndividualVO paramIvo = sourceVO;

		tempIvo.setParticipantId(paramIvo.getParticipantId());
		tempIvo.setOldParticipantId(paramIvo.getOldParticipantId());
		tempIvo.setAppellative(paramIvo.getAppellative());//称呼
		tempIvo.setBirthDate(paramIvo.getBirthDate());//出生日期
		tempIvo.setBirthDateDisplayValue(paramIvo.getBirthDateDisplayValue());//出生日期显示值

		tempIvo.setCertificateType(paramIvo.getCertificateType());//证件类型id
		tempIvo.setCertificateTypeCode(paramIvo.getCertificateTypeCode());//证件类型编号
		tempIvo.setCertificateTypeName(paramIvo.getCertificateTypeName());//证件类型名称
		tempIvo.setCertificateNo(paramIvo.getCertificateNo());//证件号码

		tempIvo.setCorporation(paramIvo.getCorporation());//单位名称
		tempIvo.setEmail(paramIvo.getEmail());//电子邮件
		tempIvo.setEmergencyMan(paramIvo.getEmergencyMan());//紧急联系人
		tempIvo.setEmergencyPhone(paramIvo.getEmergencyPhone());//紧急联系电话
		tempIvo.setHomeplace(paramIvo.getHomeplace());//籍贯

		tempIvo.setInterest(paramIvo.getInterest());//兴趣爱好
		tempIvo.setInterestNameStr(this.customerService.assemblyInterestNameString(paramIvo.getInterest()));
		tempIvo.setLinkAddress(paramIvo.getLinkAddress());//联系地址
		tempIvo.setParticipantName(paramIvo.getParticipantName());//姓名
		tempIvo.setProfession(paramIvo.getProfession());//获取职业
		tempIvo.setRegisterCar(paramIvo.getRegisterCar());//获取车辆情况
		tempIvo.setRegisterPlace(paramIvo.getRegisterPlace());//户口所在地
		tempIvo.setRemark(paramIvo.getRemark());//备注
		tempIvo.setSex(paramIvo.getSex());//性别
		tempIvo.setSexDisplayValue(this.getSexDisplayValueById(paramIvo.getSex()));//性别显示值
		tempIvo.setTelephone(paramIvo.getTelephone());//联系电话

	}

	/**
	 * 功能描述：修改一个组织住户属性值
	 *
	 *  @author 付湘辉
	 *  Created on 2008-05-29
	 *
	 * @param sourceVO 不可更改
	 * @param targetVO
	 */
	private void editOrganizationCustomerInner(final OrganizationVO sourceVO, OrganizationVO targetVO) {

		targetVO.setParticipantId(sourceVO.getParticipantId());
		targetVO.setOldParticipantId(sourceVO.getOldParticipantId());
		targetVO.setParticipantName(sourceVO.getParticipantName());//企业名称？
		targetVO.setTelephone(sourceVO.getTelephone());//联系电话
		targetVO.setAddress(sourceVO.getAddress());//企业地址
		targetVO.setZip(sourceVO.getZip());//邮编
		targetVO.setOrganizationLinkMan(sourceVO.getOrganizationLinkMan());//联系人

		//	设置法人信息
		targetVO.setCorporationId(sourceVO.getCorporationId());
		targetVO.setOldCorporationId(sourceVO.getOldCorporationId());
		targetVO.setCertificateType(sourceVO.getCertificateType());//法人证件类型id
		targetVO.setCertificateTypeCode(sourceVO.getCertificateTypeCode());//法人证件类型编号
		targetVO.setCertificateTypeName(sourceVO.getCertificateTypeName());//法人证件类型名称
		targetVO.setCertificateNo(sourceVO.getCertificateNo());//法人证件号码
		targetVO.setOrganizationPersonName(sourceVO.getOrganizationPersonName());//法人姓名
		targetVO.setAppellative(sourceVO.getAppellative());//法人称呼
		targetVO.setSex(sourceVO.getSex());//法人性别
		targetVO.setSexDisplayValue(this.getSexDisplayValueById(sourceVO.getSex()));//性别显示值（法人）
		targetVO.setOrganizationPersonPhone(sourceVO.getOrganizationPersonPhone());//法人联系电话
		targetVO.setCorporationBirthDate(sourceVO.getCorporationBirthDate());//出生日期（法人）
		targetVO.setRegisterPlace(sourceVO.getRegisterPlace());//户口所在地（法人）
		targetVO.setLinkAddress(sourceVO.getLinkAddress());//联系地址（法人）
		targetVO.setEmail(sourceVO.getEmail());//联系邮件（法人）
		targetVO.setRemark(sourceVO.getRemark());//备注（法人）

		//设置委托人/代理人信息
		targetVO.setConsignerId(sourceVO.getConsignerId());
		targetVO.setOldConsignerId(sourceVO.getOldConsignerId());
		targetVO.setConsignerName(sourceVO.getConsignerName());//姓名（代理人）
		targetVO.setConsignerSex(sourceVO.getConsignerSex());//性别（代理人）
		targetVO.setConsignerSexDisplayValue(this.getSexDisplayValueById(sourceVO.getConsignerSex()));//性别显示值（代理人）
		targetVO.setConsignerCertificateType(sourceVO.getConsignerCertificateType());//证件类型id（代理人）
		targetVO.setConsignerCertificateTypeCode(sourceVO.getConsignerCertificateTypeCode());//证件类型编号（代理人）
		targetVO.setConsignerCertificateTypeName(sourceVO.getConsignerCertificateTypeName());//证件类型名称（代理人）
		targetVO.setConsignerCertificateNo(sourceVO.getConsignerCertificateNo());//证件号码（代理人）
		targetVO.setConsignerAddress(sourceVO.getConsignerAddress());//联系地址（代理人）
		targetVO.setConsignerEmail(sourceVO.getConsignerEmail());//电子邮件（代理人）
		targetVO.setConsignerPhone(sourceVO.getConsignerPhone());//联系电话（代理人）
		targetVO.setConsignerHomeplace(sourceVO.getConsignerHomeplace());//籍贯（代理人）
	}

	/**
	 * 功能描述: 生成一个住户房屋索引,参数list所包含的元素必须是一个已经实现ICacheManage接口的对象。<br>
	 * 在调用时会确保list不是一个空引用。
	 *
	 *
	 * @author 付湘辉
	 * Created on:2008-6-3
	 *
	 * 修改原因：
	 * @param list
	 * @return Integer 0或正整数，如果小于0表示有错误
	 */
	private Integer generationCacheIndex(LinkedList<ICacheManage> list){
		if (list == null) {
			return -1;
		}else if (0 == list.size()) {
			return 0;
		}

		Integer max = 0;

		for (ICacheManage manage : list) {
			if (max < manage.getIndex()) {
				max = manage.getIndex();
			}
		}

		return max + 1;
	}

	/**
	 * Function: 生成CustomerHouseVO的JSON样式字符串
	 * @param house
	 * @return
	 * Create author:燕大为
	 * Create on:2008-6-13
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	private String generationHouseJSON(List<CustomerHouseVO> houseList)
	{
		StringBuffer jsonStr=new StringBuffer("{");
		String houseID = "";
		String houseNumber = "";
		StringBuffer ownerName = new StringBuffer("");
		for(CustomerHouseVO house : houseList)
		{
			houseID = house.getHouseId() == null ? "" : house.getHouseId()+"";
			houseNumber = house.getHouseNumber()==null ? "" : house.getHouseNumber();
			if(house.getOwnerName() != null)
			{
				ownerName.append(house.getOwnerName()).append(",");
			}
		}
		if(ownerName.toString().length()>0)
		{
			ownerName = ownerName.deleteCharAt(ownerName.length()-1);
		}
		jsonStr.append("\"houseId\" : \""+ houseID +"\",");
		jsonStr.append("\"houseNumber\" : \""+ houseNumber +"\",");
		jsonStr.append("\"ownerName\" : \""+ ownerName  + "\"");
		jsonStr.append("}");
		return jsonStr.toString();
	}

	/**
	 * Function:生成OrganizationVO的JSON样式字符串包括企业基本信息,法人代表,代理人信息
	 * @param ivo
	 * Create author:罗军林
	 * Create on:2008-5-30
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	private String generationOrganizationAllJSON(Object[] objs)
	{
		StringBuffer jsonStr = new StringBuffer("{");
		if(objs[0] != null && objs[0] instanceof OrganizationVO)
		{
			OrganizationVO organization  = (OrganizationVO)objs[0];
			//企业信息
			jsonStr.append("\"participantId\" : \""+ (organization.getParticipantId()==null ? "" : organization.getParticipantId())+"\",");
			jsonStr.append("\"index\":\"" + (organization.getIndex() == null ? "" : organization.getIndex()) + "\",");
			jsonStr.append("\"participantName\" : \""+ (organization.getParticipantName()==null ? "" : organization.getParticipantName()) +"\",");
			jsonStr.append("\"telephone\" : \""+ (organization.getTelephone()==null ? "" : organization.getTelephone()) +"\",");
			jsonStr.append("\"zip\" : \""+ (organization.getZip()==null ? "" : organization.getZip()) +"\",");
			jsonStr.append("\"organizationLinkMan\" : \""+ (organization.getOrganizationLinkMan()==null ? "" : organization.getOrganizationLinkMan()) + "\",");
			jsonStr.append("\"address\" : \""+ (organization.getAddress()==null ? "" : organization.getAddress()) + "\",");
			jsonStr.append("\"participantTypeCode\" : \""+ (organization.getParticipantTypeCode()==null ? "" : organization.getParticipantTypeCode()) + "\",");
		}
		if(objs[1] != null && objs[1] instanceof IndividualVO)
		{
			IndividualVO organizationPerson = (IndividualVO)objs[1];
			//法人代表信息
			jsonStr.append("\"corporationId\" : \""+ (organizationPerson.getParticipantId()==null ? "" : organizationPerson.getParticipantId())+"\",");
			jsonStr.append("\"organizationPersonName\" : \""+ (organizationPerson.getParticipantName()==null ? "" : organizationPerson.getParticipantName())+"\",");
			jsonStr.append("\"corporationBirthDate\" : \""+ (organizationPerson.getBirthDate()==null ? "" : organizationPerson.getBirthDate())+"\",");
			jsonStr.append("\"appellative\" : \""+ (organizationPerson.getAppellative()==null ? "" : organizationPerson.getAppellative())+"\",");
			jsonStr.append("\"organizationPersonPhone\" : \""+ (organizationPerson.getTelephone()==null ? "" : organizationPerson.getTelephone())+"\",");
			jsonStr.append("\"sex\" : \""+ (organizationPerson.getSex()==null ? "" : organizationPerson.getSex())+"\",");
			jsonStr.append("\"email\" : \""+ (organizationPerson.getEmail()==null ? "" : organizationPerson.getEmail())+"\",");
			jsonStr.append("\"certificateType\" : \""+ (organizationPerson.getCertificateType()==null ? "" : organizationPerson.getCertificateType())+"\",");
			jsonStr.append("\"linkAddress\" : \""+ (organizationPerson.getLinkAddress()==null ? "" : organizationPerson.getLinkAddress())+"\",");
			jsonStr.append("\"certificateNo\" : \""+ (organizationPerson.getCertificateNo()==null ? "" : organizationPerson.getCertificateNo())+"\",");
			jsonStr.append("\"remark\" : \""+ (organizationPerson.getRemark()==null ? "" : organizationPerson.getRemark())+"\",");
			jsonStr.append("\"registerPlace\" : \""+ (organizationPerson.getRegisterPlace()==null ? "" : organizationPerson.getRegisterPlace())+"\",");
		}
		if(objs[2] != null && objs[2] instanceof IndividualVO)
		{
			IndividualVO consignerPerson = (IndividualVO) objs[2];
			//代理人信息
			jsonStr.append("\"consignerId\" : \""+ (consignerPerson.getParticipantId()==null ? "" : consignerPerson.getParticipantId())+"\",");
			jsonStr.append("\"consignerName\" : \""+ (consignerPerson.getParticipantName()==null ? "" : consignerPerson.getParticipantName())+"\",");
			jsonStr.append("\"consignerPhone\" : \""+ (consignerPerson.getTelephone()==null ? "" : consignerPerson.getTelephone())+"\",");
			jsonStr.append("\"consignerSex\" : \""+ (consignerPerson.getSex()==null ? "" : consignerPerson.getSex())+"\",");
			jsonStr.append("\"consignerEmail\" : \""+ (consignerPerson.getEmail()==null ? "" : consignerPerson.getEmail())+"\",");
			jsonStr.append("\"consignerCertificateType\" : \""+ (consignerPerson.getCertificateType()==null ? "" : consignerPerson.getCertificateType())+"\",");
			jsonStr.append("\"consignerHomeplace\" : \""+ (consignerPerson.getHomeplace()==null ? "" : consignerPerson.getHomeplace())+"\",");
			jsonStr.append("\"consignerCertificateNo\" : \""+ (consignerPerson.getCertificateNo()==null ? "" : consignerPerson.getCertificateNo())+"\",");
			jsonStr.append("\"consignerAddress\" : \""+ (consignerPerson.getLinkAddress()==null ? "" : consignerPerson.getLinkAddress())+"\"");
		}
		jsonStr.append("}");
		return jsonStr.toString();
	}


	/**
	 * Function:生成OrganizationVO的JSON样式字符串
	 * @param ivo
	 * Create author:罗军林
	 * Create on:2008-5-30
	 * Edit author:傅湘辉
	 * Edit on:2008-08-01
	 * Why: 增加法人代表和委托代理人信息
	 */
	private String generationOrganizationJSON(OrganizationVO ovo) {
		StringBuffer jsonStr=new StringBuffer("{");
		jsonStr.append("\"participantId\" : \""+ (ovo.getParticipantId()==null ? "" : ovo.getParticipantId())+"\",");
		jsonStr.append("\"index\":\"" + (ovo.getIndex() == null ? "" : ovo.getIndex()) + "\",");
		jsonStr.append("\"participantName\" : \""+ (ovo.getParticipantName()==null ? "" : ovo.getParticipantName()) +"\",");
		jsonStr.append("\"telephone\" : \""+ (ovo.getTelephone()==null ? "" : ovo.getTelephone()) +"\",");
		jsonStr.append("\"zip\" : \""+ (ovo.getZip()==null ? "" : ovo.getZip()) +"\",");
		jsonStr.append("\"organizationLinkMan\" : \""+ (ovo.getOrganizationLinkMan()==null ? "" : ovo.getOrganizationLinkMan()) + "\",");
		jsonStr.append("\"address\" : \""+ (ovo.getAddress()==null ? "" : ovo.getAddress()) + "\",");
		jsonStr.append("\"participantTypeCode\" : \""+ (ovo.getParticipantTypeCode()==null ? "" : ovo.getParticipantTypeCode()) + "\"");

		//法人代表信息
		jsonStr.append("\"corporationId\" : \""+ (ovo.getCorporationId()==null ? "" : ovo.getCorporationId())+"\",");
		jsonStr.append("\"organizationPersonName\" : \""+ (ovo.getOrganizationPersonName()==null ? "" : ovo.getOrganizationPersonName())+"\",");
		jsonStr.append("\"corporationBirthDate\" : \""+ (ovo.getCorporationBirthDate()==null ? "" : ovo.getCorporationBirthDate())+"\",");
		jsonStr.append("\"appellative\" : \""+ (ovo.getAppellative()==null ? "" : ovo.getAppellative())+"\",");
		jsonStr.append("\"organizationPersonPhone\" : \""+ (ovo.getOrganizationPersonPhone()==null ? "" : ovo.getOrganizationPersonPhone())+"\",");
		jsonStr.append("\"sex\" : \""+ (ovo.getSex()==null ? "" : ovo.getSex())+"\",");
		jsonStr.append("\"email\" : \""+ (ovo.getEmail()==null ? "" : ovo.getEmail())+"\",");
		jsonStr.append("\"certificateType\" : \""+ (ovo.getCertificateType()==null ? "" : ovo.getCertificateType())+"\",");
		jsonStr.append("\"linkAddress\" : \""+ (ovo.getLinkAddress()==null ? "" : ovo.getLinkAddress())+"\",");
		jsonStr.append("\"certificateNo\" : \""+ (ovo.getCertificateNo()==null ? "" : ovo.getCertificateNo())+"\",");
		jsonStr.append("\"remark\" : \""+ (ovo.getRemark()==null ? "" : ovo.getRemark())+"\",");
		jsonStr.append("\"registerPlace\" : \""+ (ovo.getRegisterPlace()==null ? "" : ovo.getRegisterPlace())+"\",");

		//代理人信息
		jsonStr.append("\"consignerId\" : \""+ (ovo.getConsignerId()==null ? "" : ovo.getConsignerId())+"\",");
		jsonStr.append("\"consignerName\" : \""+ (ovo.getConsignerName()==null ? "" : ovo.getConsignerName())+"\",");
		jsonStr.append("\"consignerPhone\" : \""+ (ovo.getConsignerPhone()==null ? "" : ovo.getConsignerPhone())+"\",");
		jsonStr.append("\"consignerSex\" : \""+ (ovo.getConsignerSex()==null ? "" : ovo.getConsignerSex())+"\",");
		jsonStr.append("\"consignerEmail\" : \""+ (ovo.getEmail()==null ? "" : ovo.getEmail())+"\",");
		jsonStr.append("\"consignerCertificateType\" : \""+ (ovo.getConsignerCertificateType()==null ? "" : ovo.getConsignerCertificateType())+"\",");
		jsonStr.append("\"consignerHomeplace\" : \""+ (ovo.getConsignerHomeplace()==null ? "" : ovo.getConsignerHomeplace())+"\",");
		jsonStr.append("\"consignerCertificateNo\" : \""+ (ovo.getConsignerCertificateNo()==null ? "" : ovo.getConsignerCertificateNo())+"\",");
		jsonStr.append("\"consignerAddress\" : \""+ (ovo.getConsignerAddress()==null ? "" : ovo.getConsignerAddress())+"\"");

		jsonStr.append("}");
		return jsonStr.toString();
	}


	/**
	 * Function:生成ParticipantInfoVO的JSON样式字符串
	 * @param ivo
	 * Create author:罗军林
	 * Create on:2008-5-30
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	private String generationParticipantJSON(IndividualVO ivo) {
		StringBuffer jsonStr=new StringBuffer("{");
		jsonStr.append("\"participantId\" : \""+ (ivo.getParticipantId()==null ? "" : ivo.getParticipantId())+"\",");
		jsonStr.append("\"index\":\"" + (ivo.getIndex() ==null ? "" : ivo.getIndex()) +"\",");
		jsonStr.append("\"participantName\" : \""+ (ivo.getParticipantId()==null ? "" : ivo.getParticipantName()) +"\",");
		jsonStr.append("\"sex\" : \""+ (ivo.getSex()==null ? "" : ivo.getSex()) +"\",");
		jsonStr.append("\"certificateNo\" : \""+ (ivo.getCertificateNo()==null ? "" : ivo.getCertificateNo()) +"\",");
		jsonStr.append("\"appellative\" : \""+ (ivo.getAppellative()==null ? "" : ivo.getAppellative()) + "\",");
		jsonStr.append("\"telephone\" : \""+ (ivo.getTelephone()==null ? "" : ivo.getTelephone()) + "\",");
		jsonStr.append("\"email\" : \""+ (ivo.getEmail()==null ? "" : ivo.getEmail()) + "\",");
		jsonStr.append("\"remark\" : \""+ (ivo.getRemark()==null ? "" : ivo.getRemark()) + "\",");
		jsonStr.append("\"homeplace\" : \""+ (ivo.getHomeplace()==null ? "" : ivo.getHomeplace()) + "\",");
		jsonStr.append("\"birthDate\" : \""+ (ivo.getBirthDate()==null ? "" : ivo.getBirthDate()) + "\",");
		jsonStr.append("\"linkAddress\" : \""+ (ivo.getLinkAddress()==null ? "" : ivo.getLinkAddress()) + "\",");
		jsonStr.append("\"profession\" : \""+ (ivo.getProfession()==null ? "" : ivo.getProfession()) + "\",");
		jsonStr.append("\"emergencyMan\" : \""+ (ivo.getEmergencyMan()==null ? "" : ivo.getEmergencyMan()) + "\",");
		jsonStr.append("\"emergencyPhone\" : \""+ (ivo.getEmergencyPhone()==null ? "" : ivo.getEmergencyPhone()) + "\",");
		jsonStr.append("\"registerCar\" : \""+ (ivo.getRegisterCar()==null ? "" : ivo.getRegisterCar()) + "\",");
		jsonStr.append("\"interest\" : ["+ (ivo.getInterest()==null ? "" : ivo.getInterest()) + "],");
		jsonStr.append("\"corporation\" : \""+ (ivo.getCorporation()==null ? "" : ivo.getCorporation()) + "\",");
		jsonStr.append("\"registerPlace\" : \""+ (ivo.getRegisterPlace()==null ? "" : ivo.getRegisterPlace()) + "\"");
		jsonStr.append("}");
		return jsonStr.toString();
	}

	/**
	 *
	* Function:将查询的数组转换为显示VO
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	private List<ResidentVO> generationResidentViewData(List<Object[]> residentList){
		List<ResidentVO> tempList = new ArrayList<ResidentVO>();
		ResidentVO residentVO = null;
		for (Object[] item : residentList) {
			residentVO = new ResidentVO();
			residentVO.setHouseNumber((String)item[0]);
			residentVO.setCustomerName((String)item[1]);
			residentVO.setCustomerType((String)item[2]);
			if(item[3] != null) {
				residentVO.setInDate(item[3].toString());
			}
			if(item[4] != null) {
				residentVO.setOutDate(item[4].toString());
			}
			residentVO.setIdCode((String)item[5]);//证件名
			residentVO.setIdNO((String)item[6]);
			residentVO.setTelephone((String)item[7]);
			if(item[11] != null ) {
				residentVO.setParticipantId(Long.valueOf(item[11].toString()));
			}
			if(item[13] != null) {
				residentVO.setHouseId(Long.valueOf(item[13].toString()));
			}
			if(item[9] != null) {
				residentVO.setCustomerID(Long.valueOf(item[9].toString()));
			}
			tempList.add(residentVO);
		}
		return tempList;
	}

	/**
	 * 功能描述: 得到缓存中已删除的住户房屋资料列表
	 *
	 * @author 付湘辉
	 * Created on:2008-5-30
	 *
	 * Edit on：
	 * @param key 缓存key值
	 * @return LinkedList<CustomerVO> 返回结果
	 */
	private LinkedList<CustomerHouseVO> getDeletedCustomerHouseListCacheHerebyFlag(String key) {
		if (BlankUtil.isBlank(key)) {
			key = CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL;
		}

		//得到全部的
		LinkedList<CustomerHouseVO> allList= new LinkedList<CustomerHouseVO>(this.getCustomerHouseListCacheHerebyFlag(key, false));

		//得到未删除的
		LinkedList<CustomerHouseVO> noDelList = this.getCustomerHouseListCacheHerebyFlag(key, true);

		//把缓存中住户资料操作状态为未删除的过滤掉
		if (allList != null && noDelList != null) {
			allList.removeAll(noDelList);
		}

		return allList;
	}

	/**
	 * 功能描述: 获取","分割的房屋字符串,在入住时,要求检测有入住没搬出的记录,查询出来的数据第一项是房号<br>
	 * @param list
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-11-21  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private String getHouseNumberList(List<ClientRHouseDO> list){
		if(BlankUtil.isBlank(list)){
			return null;
		}
		StringBuffer houseNumbers = new StringBuffer();
		Iterator<ClientRHouseDO> iterator = list.iterator();
		if(iterator.hasNext()){
			houseNumbers.append(iterator.next().getHouse().getHouseNumber());
		}
		while(iterator.hasNext()){
			houseNumbers.append(SysrefcodeDO.CONSTANTS_COMMA).append(iterator.next().getHouse().getHouseNumber());
		}

		return houseNumbers.toString();
	}
	/**
	 * 功能描述: 判断一个住户是不是存在于缓存中的已被置为删除状态的数据，
	 * 如果是，取消删除状态 <br>
	 * @param key
	 * @param customerHouseVo
	 * @return CustomerVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-8-1  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private CustomerVO JudgeResumDeleteCustomerFromCache(String key,CustomerVO customerVo){
		List<CustomerVO> list = this.getDeletedCustomerBaseListCacheHerebyFlag(key);

		for (CustomerVO tempchvo : list) {
			//如果存在于缓存中，是删除状态的，则恢复过来，并设置持久属性为SAVED，状态属性为EDIT
			if (customerVo.equals(tempchvo)) {
				tempchvo.setHasSave(ICacheManage.SAVED);
				tempchvo.setOpratorStatus(ICacheManage.EDIT);
				return tempchvo;
			}
		}

		return null;
	}

	/**
	 * 功能描述: 判断一个房屋是不是存在于缓存中的已被置为删除状态的数据，
	 * 如果是，取消删除状态 <br>
	 * @param key
	 * @param customerHouseVo
	 * @return CustomerHouseVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-8-1  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private CustomerHouseVO JudgeResumDeleteHouseFromCache(String key,CustomerHouseVO customerHouseVo){
		CustomerHouseVO tempchvo = this.getOneCustomerHouseByHouseIdFromCache(key, customerHouseVo.getHouseId());
		if (BlankUtil.isBlank(tempchvo)) {
			return null;
		}

		//如果存在于缓存中，是删除状态的，则恢复过来，并设置持久属性为SAVED，状态属性为EDIT
		if (ICacheManage.DELETE.equals(tempchvo.getOpratorStatus())) {
			tempchvo.setHasSave(ICacheManage.SAVED);
			tempchvo.setOpratorStatus(ICacheManage.EDIT);
			return tempchvo;
		}

		return null;
	}

	/** Function:根据查询条件和分页信息查询并将查询相应信息写入request中
	 * @param custsearchVO
	 * @param pageNO
	 * @param pageSize
	 * @return
	 * Create author:罗军林
	 * Create on:2008-6-12
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	private String mySearch(CustSearchVO custsearchVO, Integer pageNO, Integer pageSize) {
		// 查询条件封装
		String sortStr = ExtremeUtils.getOrderString(this.getRequest());
		custsearchVO.setOrderString(sortStr);

		//查询
		Page page=this.customerService.queryCustomerInfo(custsearchVO, pageNO, pageSize);

		this.setAttribute("customerList", page.getResult());
		this.setAttribute("totalRows", ((Long)page.getTotalCount()).intValue());
		return "renderCustomerList";
	}

	/** 功能描述:  <br>
	 * @param sourceCH
	 * @param targetCH
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-10  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private void setupBankAccountValues(final CustomerHouseVO sourceCH, CustomerHouseVO targetCH) {
		targetCH.setAccountOwner(sourceCH.getAccountOwner()==null?null:sourceCH.getAccountOwner());// 开户人
		targetCH.setBankId(sourceCH.getBankId()==null?null:sourceCH.getBankId());// 银行ID
		targetCH.setBankName(sourceCH.getBankName()==null?null:sourceCH.getBankName());// 银行名称
		targetCH.setBankNumber(sourceCH.getBankNumber()==null?null:sourceCH.getBankNumber());//银行帐号
		targetCH.setContactNumber(sourceCH.getContactNumber()==null?null:sourceCH.getContactNumber());//合同号
	}

	/** 功能描述: 验证个人与产权房是否有关系 <br>
	 * @param certificateNo
	 * @param certificateType
	 * @param houseKey
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 * @param oldCustomerId TODO
	 * @param newCustomerId TODO
	 * @param operType TODO
	 * @param index TODO
	*/
	private void validateIndividualAndHouse(String certificateNo, Long certificateType, String houseKey, Long oldCustomerId, Long newCustomerId, String operType, Integer index) {
		CustomerVO customerVo = this.customerService.queryParticipant(certificateType.toString(), certificateNo);
		if(!BlankUtil.isBlank(customerVo)){
			this.validationHouseAndCustomerOnSave(customerVo,houseKey);
		}
	}

	/**
	 * 功能描述: 验证指定的证件类型及号码是否是缓存中的个人信息之一。<br>
	 * @param certificateType
	 * @param certificateNo
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 * @param oldIndividualId TODO
	 * @param newIndividualId TODO
	 * @param operateType TODO
	 * @param index TODO
	 */
	private String validateIndividualIsExistCache(Long certificateType,
												   String certificateNo,
												   Long oldIndividualId,
												   Long newIndividualId,
												   String operateType,
												   Integer index) {
		String isExist = IS_FULL_NOTEXIST;
		CustomerVO customerVo = this.getOneCustomerBaseBycertificateTypeAndNoFromCache(
										CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,
										certificateType,
										certificateNo);

		if (BlankUtil.isBlank(customerVo)) {
			return isExist;
		}

		if (CustomerAction.AT_ADD.equalsIgnoreCase(operateType)) {
			isExist=IS_FULL_EXIST;
		}else if (CustomerAction.AT_ADD_EDIT.equalsIgnoreCase(operateType)) {
			if ( ( BlankUtil.isBlank(oldIndividualId)&& !BlankUtil.isBlank(customerVo.getParticipantId()) )
					|| ( !BlankUtil.isBlank(oldIndividualId) && !oldIndividualId.equals(customerVo.getParticipantId()) )
					) {
				isExist=IS_FULL_EXIST;
			}else if (BlankUtil.isBlank(oldIndividualId)
					&& BlankUtil.isBlank(customerVo.getParticipantId())) {

				if (!BlankUtil.isBlank(index)) {
					if (BlankUtil.isBlank(oldIndividualId)
							&& BlankUtil.isBlank(customerVo.getParticipantId())) {
						if (!index.equals(customerVo.getIndex())) {
							isExist=IS_FULL_EXIST;
						}else{
							isExist=IS_ONESELF_EXIST;
						}
					}
				}
			}else if (!BlankUtil.isBlank(oldIndividualId) && oldIndividualId.equals(customerVo.getParticipantId())) {
				if (!BlankUtil.isBlank(index)) {
					if (!index.equals(customerVo.getIndex())) {
						isExist=IS_FULL_EXIST;
					}else{
						isExist=IS_ONESELF_EXIST;
					}
				}
			}
		}else if (CustomerAction.AT_EDIT.equalsIgnoreCase(operateType)) {
			if ( ( BlankUtil.isBlank(oldIndividualId)&& !BlankUtil.isBlank(customerVo.getParticipantId()) )
					|| ( !BlankUtil.isBlank(oldIndividualId) && !oldIndividualId.equals(customerVo.getParticipantId()) ) ) {
				isExist=IS_FULL_EXIST;
			}else if ( !BlankUtil.isBlank(oldIndividualId) && oldIndividualId.equals(customerVo.getParticipantId()) ) {
				isExist=IS_ONESELF_EXIST;
			}
		}

		if (IS_FULL_EXIST.equalsIgnoreCase(isExist)) {
			// 这个人已经存在于缓存中了
			throw new BusinessException("customer:owner_exist_same_type_no_exception",
					BusinessException.WARNING);
		}

		return isExist;
	}

	/**
	* Function:在修改业主页面，输入证件类型和证件号码后，
	* 直接点保存的后台验证
	 * @param oldIndividualId
	 * @param newIndividualId
	 * @param operateType
	 * @param
	* Create author:yixianjian
	* Create on:2008-7-4
	* Edit author:付湘辉
	* Edit on:2008-10-24
	* Why:更改注释
	*/
	private void validateIndividualLoadOnEditSave(IndividualVO individualVO,
										  		  String houseKey, String operateType){
//		if (this.isValidateIndividualLoadForRenderText==1) {
//			this.isValidateIndividualLoadForRenderText=0;
//			return;
//		}
//		this.isValidateIndividualLoadForRenderText=0;
		Boolean res =checkIsDeleteStatus(individualVO.getCertificateNo(), individualVO.getCertificateType());
		if (res) {
			return;
		}
		String isExist = "";
		isExist = this.validateIndividualIsExistCache(individualVO.getCertificateType(),
												  individualVO.getCertificateNo(),
												  individualVO.getOldParticipantId(),
												  individualVO.getParticipantId(),
												  operateType,
												  individualVO.getIndex());
		if (IS_FULL_NOTEXIST.equalsIgnoreCase(isExist)) {
			this.validateIndividualAndHouse(individualVO.getCertificateNo(), individualVO.getCertificateType(), houseKey, null, null, null, null);
		}

	}

	/**
	* Function:在新增业主页面输入证件类型和证件号码后，直接点保存的后台验证。 <br>
	* 检查指定的个人信息是否在缓存中被置为删除状态，如果是删除状态，直接返回，不再进行下一步验证。 <br>
	* 否则，验证其在缓存中是否存在，或者虽然存在但没做任何改动。
	* 如果得到此信息在缓存中根本不存在，则再检查其是否与住房列表中的住房已建立关系。
	 * @param individualVO TODO
	 * @param operateType TODO
	 * @param
	* Create author:yixianjian
	* Create on:2008-7-4
	* Edit author:付湘辉
	* Edit on:2008-10-24
	* Why:更改注释
	*/
	private void validateIndividualLoadOnSave(IndividualVO individualVO,
										  		String houseKey,
										  		String operateType){
		Boolean res =checkIsDeleteStatus(individualVO.getCertificateNo(), individualVO.getCertificateType());
		if (res) {
			return;
		}
		String isExist = "";
		isExist = this.validateIndividualIsExistCache(individualVO.getCertificateType(),
													  individualVO.getCertificateNo(),
													  individualVO.getOldParticipantId(),
													  individualVO.getParticipantId(),
													  operateType,
													  individualVO.getIndex());
		if (IS_FULL_NOTEXIST.equalsIgnoreCase(isExist)) {
			this.validateIndividualAndHouse(individualVO.getCertificateNo(), individualVO.getCertificateType(), houseKey, null, null, null, null);
		}
	}

	/** 功能描述: 验证企业与产权房是否有关系 <br>
	 * @param participantName
	 * @param houseKey
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private void validateOrgAndHouse(String participantName, String houseKey) {
		CustomerVO customerVo = this.customerService.findOrganizationByName(participantName);
		if(!BlankUtil.isBlank(customerVo)){
			this.validationHouseAndCustomerOnSave(customerVo,houseKey);
		}
	}

	/**
	 * <b>功能描述</b>:
	 * <p>在新建或修改企业业主时，输入企业名称后，
	 * 点击保存时验证。
	 * @param organizationVO TODO
	 * @param operateType TODO
	 * @author
	 * Create author:付湘辉 <br>
	 * Create on:2008-7-30  <br>
	 * Edit author:付湘辉  <br>
	 * Edit on:2008-10-24  <br>
	 * Why:  修改注释   <br>
	 */
	private void validateOrganizationOnEditSave(OrganizationVO organizationVO,
												String houseKey, String operateType){
//		判断是否是在缓存中被置删除状态的
		Boolean res = this.checkIsDeleteStatus(organizationVO.getParticipantName());
		if (res) return;

		String isExist = this.validateOrgIsExistCache(organizationVO.getParticipantName(), organizationVO.getOldParticipantId(), organizationVO.getParticipantId(), operateType, organizationVO.getIndex());

		if (IS_FULL_NOTEXIST.equalsIgnoreCase(isExist)) {
			this.validateOrgAndHouse(organizationVO.getParticipantName(), houseKey);
		}
	}

	/**
	 * <b>功能描述</b>:
	 * <p>在新建或修改企业业主时，输入企业名称后，
	 * 点击保存时验证。
	 * @param participantName
	 * @param oldOrgId TODO
	 * @param newOrgId TODO
	 * @author
	 * Create author:付湘辉 <br>
	 * Create on:2008-7-30  <br>
	 * Edit author:付湘辉  <br>
	 * Edit on:2008-10-24  <br>
	 * Why:  修改注释   <br>
	 */
	private void validateOrganizationOnSave(String participantName,
											Long oldOrgId,
											Long newOrgId,
											String houseKey){
//		判断是否是在缓存中被置删除状态的
		Boolean res = this.checkIsDeleteStatus(participantName);
		if (res) return;

		String isExist = this.validateOrgIsExistCache(participantName, oldOrgId, newOrgId, CustomerAction.AT_ADD, null);

		if (IS_FULL_NOTEXIST.equalsIgnoreCase(isExist)) {
			this.validateOrgAndHouse(participantName, houseKey);
		}
	}
	/**
	 * 功能描述: 验证指定的企业名称是否是缓存中的企业信息之一。<br>
	 * @param participantName
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 * @param oldOrgId TODO
	 * @param newOrgId TODO
	 * @param operateType TODO
	 * @param index TODO
	 */
	private String validateOrgIsExistCache(String participantName, Long oldOrgId, Long newOrgId, String operateType, Integer index){
		CustomerVO customerVo = this.getOneCustomerBaseByOrgNameFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, participantName);

		String isExist = IS_FULL_NOTEXIST;
		if (BlankUtil.isBlank(customerVo)) {
			return isExist;
		}

		if (CustomerAction.AT_ADD.equalsIgnoreCase(operateType)) {
			isExist=IS_FULL_EXIST;
		}else if (CustomerAction.AT_ADD_EDIT.equalsIgnoreCase(operateType)) {
			if ( ( BlankUtil.isBlank(oldOrgId)&& !BlankUtil.isBlank(customerVo.getParticipantId()) )
					|| ( !BlankUtil.isBlank(oldOrgId) && !oldOrgId.equals(customerVo.getParticipantId()) )
					) {
				isExist=IS_FULL_EXIST;
			}else if (BlankUtil.isBlank(oldOrgId)
					&& BlankUtil.isBlank(customerVo.getParticipantId())) {

				if (!BlankUtil.isBlank(index)) {
					if (BlankUtil.isBlank(oldOrgId)
							&& BlankUtil.isBlank(customerVo.getParticipantId())) {
						if (!index.equals(customerVo.getIndex())) {
							isExist=IS_FULL_EXIST;
						}else{
							isExist=IS_ONESELF_EXIST;
						}
					}
				}
			}else if (!BlankUtil.isBlank(oldOrgId) && oldOrgId.equals(customerVo.getParticipantId())) {
				if (!BlankUtil.isBlank(index)) {
					if (!index.equals(customerVo.getIndex())) {
						isExist=IS_FULL_EXIST;
					}else{
						isExist=IS_ONESELF_EXIST;
					}
				}
			}
		}else if (CustomerAction.AT_EDIT.equalsIgnoreCase(operateType)) {
			if ( ( BlankUtil.isBlank(oldOrgId)&& !BlankUtil.isBlank(customerVo.getParticipantId()) )
					|| ( !BlankUtil.isBlank(oldOrgId) && !oldOrgId.equals(customerVo.getParticipantId()) ) ) {
				isExist=IS_FULL_EXIST;
			}else if ( !BlankUtil.isBlank(oldOrgId) && oldOrgId.equals(customerVo.getParticipantId()) ) {
				isExist=IS_ONESELF_EXIST;
			}
		}

		if (IS_FULL_EXIST.equalsIgnoreCase(isExist)) {
			// 这个企业已经存在于缓存中了
			throw new BusinessException("customer:owner_exist_same_type_no_exception",
						BusinessException.WARNING);
		}

		return isExist;
	}

	/** 功能描述:  <br>
	 * @param customerVo
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-7-30  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private void validationHouseAndCustomerOnSave(CustomerVO customerVo,String houseKey) {
		List<CustomerHouseVO> list = this.getCustomerHouseListCacheHerebyFlag(houseKey, true);
		if (!BlankUtil.isBlank(list)) {
			Long participantId= customerVo.getParticipantId();
			for (CustomerHouseVO houseVO : list) {
				this.customerService.validateParticipantRoleInSameHouse(participantId, houseVO);//     -----到后台验证
			}
		}
	}
}
